github.com/prattmic/llgo-embedded@v0.0.0-20150820070356-41cfecea0e1e/third_party/gofrontend/libgo/runtime/go-strplus.c (about)

     1  /* go-strplus.c -- the go string append function.
     2  
     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.  */
     6  
     7  #include "runtime.h"
     8  #include "arch.h"
     9  #include "malloc.h"
    10  
    11  String
    12  __go_string_plus (String s1, String s2)
    13  {
    14    int len;
    15    byte *retdata;
    16    String ret;
    17  
    18    if (s1.len == 0)
    19      return s2;
    20    else if (s2.len == 0)
    21      return s1;
    22  
    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;
    30  }