diff options
author | Damian Gryski <[email protected]> | 2024-10-03 12:03:32 -0700 |
---|---|---|
committer | Ayke <[email protected]> | 2024-10-24 13:07:17 +0200 |
commit | 6e6507bf77466754c8e949809a4e62569c085c90 (patch) | |
tree | d5b3224a69c9223fd1957a855022294f8922683d /src/runtime | |
parent | b8fe75a9dd4949a08b78b2f3dd06fa3c697573dd (diff) | |
download | tinygo-6e6507bf77466754c8e949809a4e62569c085c90.tar.gz tinygo-6e6507bf77466754c8e949809a4e62569c085c90.zip |
runtime: add gc layout info for some basic types
Diffstat (limited to 'src/runtime')
-rw-r--r-- | src/runtime/slice.go | 9 | ||||
-rw-r--r-- | src/runtime/string.go | 9 |
2 files changed, 13 insertions, 5 deletions
diff --git a/src/runtime/slice.go b/src/runtime/slice.go index 7d804b11b..c9603643a 100644 --- a/src/runtime/slice.go +++ b/src/runtime/slice.go @@ -3,6 +3,7 @@ package runtime // This file implements compiler builtins for slices: append() and copy(). import ( + "internal/gclayout" "math/bits" "unsafe" ) @@ -47,7 +48,13 @@ func sliceGrow(oldBuf unsafe.Pointer, oldLen, oldCap, newCap, elemSize uintptr) // memory allocators, this causes some difficult to debug issues. newCap = 1 << bits.Len(uint(newCap)) - buf := alloc(newCap*elemSize, nil) + var layout unsafe.Pointer + // less type info here; can only go off element size + if elemSize < unsafe.Sizeof(uintptr(0)) { + layout = gclayout.NoPtrs + } + + buf := alloc(newCap*elemSize, layout) if oldLen > 0 { // copy any data to new slice memmove(buf, oldBuf, oldLen*elemSize) diff --git a/src/runtime/string.go b/src/runtime/string.go index aeefe1d4f..54485dfc2 100644 --- a/src/runtime/string.go +++ b/src/runtime/string.go @@ -3,6 +3,7 @@ package runtime // This file implements functions related to Go strings. import ( + "internal/gclayout" "unsafe" ) @@ -59,7 +60,7 @@ func stringConcat(x, y _string) _string { return x } else { length := x.length + y.length - buf := alloc(length, nil) + buf := alloc(length, gclayout.NoPtrs) memcpy(buf, unsafe.Pointer(x.ptr), x.length) memcpy(unsafe.Add(buf, x.length), unsafe.Pointer(y.ptr), y.length) return _string{ptr: (*byte)(buf), length: length} @@ -72,7 +73,7 @@ func stringFromBytes(x struct { len uintptr cap uintptr }) _string { - buf := alloc(x.len, nil) + buf := alloc(x.len, gclayout.NoPtrs) memcpy(buf, unsafe.Pointer(x.ptr), x.len) return _string{ptr: (*byte)(buf), length: x.len} } @@ -83,7 +84,7 @@ func stringToBytes(x _string) (slice struct { len uintptr cap uintptr }) { - buf := alloc(x.length, nil) + buf := alloc(x.length, gclayout.NoPtrs) memcpy(buf, unsafe.Pointer(x.ptr), x.length) slice.ptr = (*byte)(buf) slice.len = x.length @@ -100,7 +101,7 @@ func stringFromRunes(runeSlice []rune) (s _string) { } // Allocate memory for the string. - s.ptr = (*byte)(alloc(s.length, nil)) + s.ptr = (*byte)(alloc(s.length, gclayout.NoPtrs)) // Encode runes to UTF-8 and store the resulting bytes in the string. index := uintptr(0) |