2010-12-03 05:34:57 +01:00
|
|
|
/* go-strplus.c -- the go string append function.
|
|
|
|
|
|
|
|
Copyright 2009 The Go Authors. All rights reserved.
|
|
|
|
Use of this source code is governed by a BSD-style
|
|
|
|
license that can be found in the LICENSE file. */
|
|
|
|
|
|
|
|
#include "runtime.h"
|
2011-10-27 01:57:58 +02:00
|
|
|
#include "arch.h"
|
2010-12-03 05:34:57 +01:00
|
|
|
#include "malloc.h"
|
|
|
|
|
2012-11-01 04:02:13 +01:00
|
|
|
String
|
|
|
|
__go_string_plus (String s1, String s2)
|
2010-12-03 05:34:57 +01:00
|
|
|
{
|
|
|
|
int len;
|
2012-11-01 04:02:13 +01:00
|
|
|
byte *retdata;
|
|
|
|
String ret;
|
2010-12-03 05:34:57 +01:00
|
|
|
|
2012-11-01 04:02:13 +01:00
|
|
|
if (s1.len == 0)
|
2010-12-03 05:34:57 +01:00
|
|
|
return s2;
|
2012-11-01 04:02:13 +01:00
|
|
|
else if (s2.len == 0)
|
2010-12-03 05:34:57 +01:00
|
|
|
return s1;
|
|
|
|
|
2012-11-01 04:02:13 +01:00
|
|
|
len = s1.len + s2.len;
|
2011-03-17 00:05:44 +01:00
|
|
|
retdata = runtime_mallocgc (len, FlagNoPointers, 1, 0);
|
2012-11-01 04:02:13 +01:00
|
|
|
__builtin_memcpy (retdata, s1.str, s1.len);
|
|
|
|
__builtin_memcpy (retdata + s1.len, s2.str, s2.len);
|
|
|
|
ret.str = retdata;
|
|
|
|
ret.len = len;
|
2010-12-03 05:34:57 +01:00
|
|
|
return ret;
|
|
|
|
}
|