aboutsummaryrefslogtreecommitdiff
path: root/libgo/runtime/go-strplus.c
blob: 13915e3e67395d14ffed315248d2131cebd35730 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
/* 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"

String
__go_string_plus (String s1, String s2)
{
  int len;
  byte *retdata;
  String ret;

  if (s1.len == 0)
    return s2;
  else if (s2.len == 0)
    return s1;

  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;
  return ret;
}