go-strplus.c 685 B

12345678910111213141516171819202122232425262728293031
  1. /* go-strplus.c -- the go string append function.
  2. Copyright 2009 The Go Authors. All rights reserved.
  3. Use of this source code is governed by a BSD-style
  4. license that can be found in the LICENSE file. */
  5. #include "runtime.h"
  6. #include "arch.h"
  7. #include "malloc.h"
  8. String
  9. __go_string_plus (String s1, String s2)
  10. {
  11. int len;
  12. byte *retdata;
  13. String ret;
  14. if (s1.len == 0)
  15. return s2;
  16. else if (s2.len == 0)
  17. return s1;
  18. len = s1.len + s2.len;
  19. retdata = runtime_mallocgc (len, 0, FlagNoScan | FlagNoZero);
  20. __builtin_memcpy (retdata, s1.str, s1.len);
  21. __builtin_memcpy (retdata + s1.len, s2.str, s2.len);
  22. ret.str = retdata;
  23. ret.len = len;
  24. return ret;
  25. }