mirror of
https://github.com/tinygo-org/tinygo.git
synced 2026-08-03 02:27:48 +00:00
gc_leaking: Don't zero out new allocations in some targets (#4302)
Wasm linear memory is always initialized to zero by definition, so there's no need to waste time zeroing out this allocation. This is the case for freshly-obtained memory from mmap(). Signed-off-by: L. Pereira <l.pereira@fastly.com>
This commit is contained in:
@@ -44,7 +44,7 @@ func alloc(size uintptr, layout unsafe.Pointer) unsafe.Pointer {
|
||||
runtimePanic("out of memory")
|
||||
}
|
||||
pointer := unsafe.Pointer(addr)
|
||||
memzero(pointer, size)
|
||||
zero_new_alloc(pointer, size)
|
||||
return pointer
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
//go:build gc.leaking && (baremetal || nintendoswitch)
|
||||
|
||||
package runtime
|
||||
|
||||
import (
|
||||
"unsafe"
|
||||
)
|
||||
|
||||
//go:inline
|
||||
func zero_new_alloc(ptr unsafe.Pointer, size uintptr) {
|
||||
memzero(ptr, size)
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
//go:build gc.leaking && !baremetal && !nintendoswitch
|
||||
|
||||
package runtime
|
||||
|
||||
import (
|
||||
"unsafe"
|
||||
)
|
||||
|
||||
//go:inline
|
||||
func zero_new_alloc(ptr unsafe.Pointer, size uintptr) {
|
||||
// Wasm linear memory is initialized to zero by default, so
|
||||
// there's no need to do anything. This is also the case for
|
||||
// fresh-allocated memory from an mmap() system call.
|
||||
}
|
||||
Reference in New Issue
Block a user