Retro68/gcc/libgo/runtime/go-strplus.c

31 lines
685 B
C
Raw Normal View History

2012-03-27 23:13:14 +00: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"
#include "arch.h"
#include "malloc.h"
2014-09-21 17:33:12 +00:00
String
__go_string_plus (String s1, String s2)
2012-03-27 23:13:14 +00:00
{
int len;
2014-09-21 17:33:12 +00:00
byte *retdata;
String ret;
2012-03-27 23:13:14 +00:00
2014-09-21 17:33:12 +00:00
if (s1.len == 0)
2012-03-27 23:13:14 +00:00
return s2;
2014-09-21 17:33:12 +00:00
else if (s2.len == 0)
2012-03-27 23:13:14 +00:00
return s1;
2014-09-21 17:33:12 +00:00
len = s1.len + s2.len;
retdata = runtime_mallocgc (len, 0, FlagNoScan | FlagNoZero);
__builtin_memcpy (retdata, s1.str, s1.len);
__builtin_memcpy (retdata + s1.len, s2.str, s2.len);
ret.str = retdata;
ret.len = len;
2012-03-27 23:13:14 +00:00
return ret;
}