mirror of
https://github.com/tinygo-org/tinygo.git
synced 2026-07-26 06:38:42 +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
Vendored
+8
-1
@@ -33,7 +33,7 @@ func main() {
|
||||
c1 := getComplex128() // OUT: object allocated on the heap: escapes at line 34
|
||||
useInterface(c1)
|
||||
|
||||
n3 := 5 // OUT: object allocated on the heap: escapes at line 39
|
||||
n3 := 5
|
||||
func() int {
|
||||
return n3
|
||||
}()
|
||||
@@ -42,6 +42,13 @@ func main() {
|
||||
|
||||
s8 := []int{3, 5, 8} // OUT: object allocated on the heap: escapes at line 44
|
||||
callVariadic(s8...)
|
||||
|
||||
n4 := 3 // OUT: object allocated on the heap: escapes at line 48
|
||||
n5 := 7 // OUT: object allocated on the heap: escapes at line 48
|
||||
func() {
|
||||
n4 = n5
|
||||
}()
|
||||
println(n4, n5)
|
||||
}
|
||||
|
||||
func derefInt(x *int) int {
|
||||
|
||||
Reference in New Issue
Block a user