mirror of
https://github.com/tinygo-org/tinygo.git
synced 2026-08-05 19:43:44 +00:00
compiler: implement clear builtin for maps
This commit is contained in:
committed by
Ron Evans
parent
a2f886a67a
commit
f1e25a18d2
Vendored
+11
@@ -15,4 +15,15 @@ func main() {
|
||||
s := []int{1, 2, 3, 4, 5}
|
||||
clear(s[:3])
|
||||
println("cleared s[:3]:", s[0], s[1], s[2], s[3], s[4])
|
||||
|
||||
// The clear builtin, for maps.
|
||||
m := map[int]string{
|
||||
1: "one",
|
||||
2: "two",
|
||||
3: "three",
|
||||
}
|
||||
clear(m)
|
||||
println("cleared map:", m[1], m[2], m[3], len(m))
|
||||
m[4] = "four"
|
||||
println("added to cleared map:", m[1], m[2], m[3], m[4], len(m))
|
||||
}
|
||||
|
||||
Vendored
+2
@@ -1,3 +1,5 @@
|
||||
min/max: -3 5
|
||||
min/max: -3.000000e+000 +5.000000e+000
|
||||
cleared s[:3]: 0 0 0 4 5
|
||||
cleared map: 0
|
||||
added to cleared map: four 1
|
||||
|
||||
Reference in New Issue
Block a user