mirror of
https://github.com/tinygo-org/tinygo.git
synced 2026-08-12 15:03:41 +00:00
compiler: do not emit nil checks for loading closure variables
Closure variables are allocated in a parent function and are thus never nil. Don't do a nil check before reading or modifying the value. This commit results in a slight reduction in code size in some test cases: calls.go, channel.go, goroutines.go, json.go, sort.go - presumably wherever closures are used.
This commit is contained in:
committed by
Ron Evans
parent
ec325c0643
commit
3edcdb5f0d
@@ -162,6 +162,10 @@ func (b *builder) createNilCheck(inst ssa.Value, ptr llvm.Value, blockPrefix str
|
||||
case *ssa.Alloc:
|
||||
// An alloc is never nil.
|
||||
return
|
||||
case *ssa.FreeVar:
|
||||
// A free variable is allocated in a parent function and is thus never
|
||||
// nil.
|
||||
return
|
||||
case *ssa.IndexAddr:
|
||||
// This pointer is the result of an index operation into a slice or
|
||||
// array. Such slices/arrays are already bounds checked so the pointer
|
||||
|
||||
Reference in New Issue
Block a user