mirror of
https://github.com/tinygo-org/tinygo.git
synced 2026-08-05 11:37:46 +00:00
compiler,runtime: use the size hint when creating a new map
It defaults to hint/8 number of buckets. This number may be tuned in the future.
This commit is contained in:
committed by
Ron Evans
parent
17c42810d0
commit
55fc7b904a
Vendored
+13
@@ -47,6 +47,18 @@ func main() {
|
||||
println(testMapArrayKey[arrKey])
|
||||
testMapArrayKey[arrKey] = 5555
|
||||
println(testMapArrayKey[arrKey])
|
||||
|
||||
// test preallocated map
|
||||
squares := make(map[int]int, 200)
|
||||
for i := 0; i < 100; i++ {
|
||||
squares[i] = i*i
|
||||
for j := 0; j <= i; j++ {
|
||||
if v := squares[j]; v != j*j {
|
||||
println("unexpected value read back from squares map:", j, v)
|
||||
}
|
||||
}
|
||||
}
|
||||
println("tested preallocated map")
|
||||
}
|
||||
|
||||
func readMap(m map[string]int, key string) {
|
||||
@@ -56,6 +68,7 @@ func readMap(m map[string]int, key string) {
|
||||
println(" ", k, "=", v)
|
||||
}
|
||||
}
|
||||
|
||||
func lookup(m map[string]int, key string) {
|
||||
value, ok := m[key]
|
||||
println("lookup with comma-ok:", key, value, ok)
|
||||
|
||||
Vendored
+1
@@ -54,3 +54,4 @@ true false 0
|
||||
42
|
||||
4321
|
||||
5555
|
||||
tested preallocated map
|
||||
|
||||
Reference in New Issue
Block a user