mirror of
https://github.com/tinygo-org/tinygo.git
synced 2026-09-01 10:19:01 +00:00
compiler, runtime: optimize zero-sized allocations
Instead of referring to an unused global, use a constant value. This is safe even when using `-gc=none` (since no actual memory gets allocated) which wasn't the case before. It should also reduce binary size by a few bytes for most programs.
This commit is contained in:
committed by
Ron Evans
parent
221ea6a54c
commit
134de98ba5
@@ -58,9 +58,6 @@ var (
|
||||
gcLock task.PMutex // lock to avoid race conditions on multicore systems
|
||||
)
|
||||
|
||||
// zeroSizedAlloc is just a sentinel that gets returned when allocating 0 bytes.
|
||||
var zeroSizedAlloc uint8
|
||||
|
||||
// Provide some abstraction over heap blocks.
|
||||
|
||||
// blockState stores the four states in which a block can be.
|
||||
@@ -405,7 +402,7 @@ func calculateHeapAddresses() {
|
||||
//go:noinline
|
||||
func alloc(size uintptr, layout unsafe.Pointer) unsafe.Pointer {
|
||||
if size == 0 {
|
||||
return unsafe.Pointer(&zeroSizedAlloc)
|
||||
return alloc_zero(size, layout)
|
||||
}
|
||||
|
||||
if interrupt.In() {
|
||||
|
||||
Reference in New Issue
Block a user