mirror of
https://github.com/tinygo-org/tinygo.git
synced 2026-08-11 06:23:39 +00:00
internal/gclayout: make gclayout values constants
The previous versions calculated at init() prevented `interp` from running in many cases, increasing compile times due to the increased need to revert the partially interpreted results and also increasing binary runtime because fewer optimizations had happened during interp.
This commit is contained in:
@@ -89,7 +89,7 @@ func alloc(size uintptr, layout unsafe.Pointer) unsafe.Pointer {
|
||||
gcLock.Lock()
|
||||
needsResumeWorld = false
|
||||
var ptr unsafe.Pointer
|
||||
if layout == gclayout.NoPtrs {
|
||||
if layout == gclayout.NoPtrs.AsPtr() {
|
||||
// This object is entirely pointer free, for example make([]int, ...).
|
||||
// Make sure the GC knows this so it doesn't scan the object
|
||||
// unnecessarily to improve performance.
|
||||
|
||||
@@ -51,7 +51,7 @@ func sliceGrow(oldBuf unsafe.Pointer, oldLen, oldCap, newCap, elemSize uintptr)
|
||||
var layout unsafe.Pointer
|
||||
// less type info here; can only go off element size
|
||||
if elemSize < unsafe.Sizeof(uintptr(0)) {
|
||||
layout = gclayout.NoPtrs
|
||||
layout = gclayout.NoPtrs.AsPtr()
|
||||
}
|
||||
|
||||
buf := alloc(newCap*elemSize, layout)
|
||||
|
||||
@@ -60,7 +60,7 @@ func stringConcat(x, y _string) _string {
|
||||
return x
|
||||
} else {
|
||||
length := x.length + y.length
|
||||
buf := alloc(length, gclayout.NoPtrs)
|
||||
buf := alloc(length, gclayout.NoPtrs.AsPtr())
|
||||
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}
|
||||
@@ -73,7 +73,7 @@ func stringFromBytes(x struct {
|
||||
len uintptr
|
||||
cap uintptr
|
||||
}) _string {
|
||||
buf := alloc(x.len, gclayout.NoPtrs)
|
||||
buf := alloc(x.len, gclayout.NoPtrs.AsPtr())
|
||||
memcpy(buf, unsafe.Pointer(x.ptr), x.len)
|
||||
return _string{ptr: (*byte)(buf), length: x.len}
|
||||
}
|
||||
@@ -84,7 +84,7 @@ func stringToBytes(x _string) (slice struct {
|
||||
len uintptr
|
||||
cap uintptr
|
||||
}) {
|
||||
buf := alloc(x.length, gclayout.NoPtrs)
|
||||
buf := alloc(x.length, gclayout.NoPtrs.AsPtr())
|
||||
memcpy(buf, unsafe.Pointer(x.ptr), x.length)
|
||||
slice.ptr = (*byte)(buf)
|
||||
slice.len = x.length
|
||||
@@ -101,7 +101,7 @@ func stringFromRunes(runeSlice []rune) (s _string) {
|
||||
}
|
||||
|
||||
// Allocate memory for the string.
|
||||
s.ptr = (*byte)(alloc(s.length, gclayout.NoPtrs))
|
||||
s.ptr = (*byte)(alloc(s.length, gclayout.NoPtrs.AsPtr()))
|
||||
|
||||
// Encode runes to UTF-8 and store the resulting bytes in the string.
|
||||
index := uintptr(0)
|
||||
|
||||
Reference in New Issue
Block a user