2014-07-29 Ed Smith-Rowland <3dw4rd@verizon.net>
[official-gcc.git] / libgo / runtime / go-strplus.c
blob13915e3e67395d14ffed315248d2131cebd35730
1 /* go-strplus.c -- the go string append function.
3 Copyright 2009 The Go Authors. All rights reserved.
4 Use of this source code is governed by a BSD-style
5 license that can be found in the LICENSE file. */
7 #include "runtime.h"
8 #include "arch.h"
9 #include "malloc.h"
11 String
12 __go_string_plus (String s1, String s2)
14 int len;
15 byte *retdata;
16 String ret;
18 if (s1.len == 0)
19 return s2;
20 else if (s2.len == 0)
21 return s1;
23 len = s1.len + s2.len;
24 retdata = runtime_mallocgc (len, 0, FlagNoScan | FlagNoZero);
25 __builtin_memcpy (retdata, s1.str, s1.len);
26 __builtin_memcpy (retdata + s1.len, s2.str, s2.len);
27 ret.str = retdata;
28 ret.len = len;
29 return ret;