mirror of
https://github.com/tinygo-org/tinygo.git
synced 2026-08-11 06:23:39 +00:00
revise defer to use heap allocations when running a variable number of times
This commit is contained in:
Vendored
+9
@@ -41,6 +41,9 @@ func main() {
|
||||
// deferred functions
|
||||
testDefer()
|
||||
|
||||
// defers in loop
|
||||
testDeferLoop()
|
||||
|
||||
// Take a bound method and use it as a function pointer.
|
||||
// This function pointer needs a context pointer.
|
||||
testBound(thing.String)
|
||||
@@ -85,6 +88,12 @@ func testDefer() {
|
||||
println("deferring...")
|
||||
}
|
||||
|
||||
func testDeferLoop() {
|
||||
for j := 0; j < 4; j++ {
|
||||
defer deferred("loop", j)
|
||||
}
|
||||
}
|
||||
|
||||
func deferred(msg string, i int) {
|
||||
println(msg, i)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user