@@ -32,6 +32,11 @@ func stringEqual(x, y string) bool {
3232 return true
3333}
3434
35+ var (
36+ // Constants for use with alloc()
37+ gcLayoutNoPtrs = unsafe .Pointer (uintptr (0x3 ))
38+ )
39+
3540// Return true iff x < y.
3641//
3742//go:nobounds
@@ -59,7 +64,7 @@ func stringConcat(x, y _string) _string {
5964 return x
6065 } else {
6166 length := x .length + y .length
62- buf := alloc (length , nil )
67+ buf := alloc (length , gcLayoutNoPtrs )
6368 memcpy (buf , unsafe .Pointer (x .ptr ), x .length )
6469 memcpy (unsafe .Add (buf , x .length ), unsafe .Pointer (y .ptr ), y .length )
6570 return _string {ptr : (* byte )(buf ), length : length }
@@ -72,7 +77,7 @@ func stringFromBytes(x struct {
7277 len uintptr
7378 cap uintptr
7479}) _string {
75- buf := alloc (x .len , nil )
80+ buf := alloc (x .len , gcLayoutNoPtrs )
7681 memcpy (buf , unsafe .Pointer (x .ptr ), x .len )
7782 return _string {ptr : (* byte )(buf ), length : x .len }
7883}
@@ -83,7 +88,7 @@ func stringToBytes(x _string) (slice struct {
8388 len uintptr
8489 cap uintptr
8590}) {
86- buf := alloc (x .length , nil )
91+ buf := alloc (x .length , gcLayoutNoPtrs )
8792 memcpy (buf , unsafe .Pointer (x .ptr ), x .length )
8893 slice .ptr = (* byte )(buf )
8994 slice .len = x .length
@@ -100,7 +105,7 @@ func stringFromRunes(runeSlice []rune) (s _string) {
100105 }
101106
102107 // Allocate memory for the string.
103- s .ptr = (* byte )(alloc (s .length , nil ))
108+ s .ptr = (* byte )(alloc (s .length , gcLayoutNoPtrs ))
104109
105110 // Encode runes to UTF-8 and store the resulting bytes in the string.
106111 index := uintptr (0 )
0 commit comments