summaryrefslogtreecommitdiff
path: root/test/codegen
diff options
context:
space:
mode:
authorKeith Randall <khr@golang.org>2022-02-06 09:43:39 -0800
committerKeith Randall <khr@golang.org>2022-03-01 23:20:30 +0000
commitaaa3d39f270d7b9957f34f3d2a68decba63beffe (patch)
tree8428a291d565262b94f73b424f8956353d910651 /test/codegen
parentd40e7bb1744507be421b80c19372b9411c9856b4 (diff)
downloadgo-git-aaa3d39f270d7b9957f34f3d2a68decba63beffe.tar.gz
cmd/compile: include all entries in map literal hint size
Currently we only include static entries in the hint for sizing the map when allocating a map for a map literal. Change that to include all entries. This will be an overallocation if the dynamic entries in the map have equal keys, but equal keys in map literals are rare, and at worst we waste a bit of space. Fixes #43020 Change-Id: I232f82f15316bdf4ea6d657d25a0b094b77884ce Reviewed-on: https://go-review.googlesource.com/c/go/+/383634 Run-TryBot: Keith Randall <khr@golang.org> Trust: Keith Randall <khr@golang.org> Trust: Josh Bleecher Snyder <josharian@gmail.com> Reviewed-by: Josh Bleecher Snyder <josharian@gmail.com> TryBot-Result: Gopher Robot <gobot@golang.org>
Diffstat (limited to 'test/codegen')
-rw-r--r--test/codegen/maps.go30
1 files changed, 30 insertions, 0 deletions
diff --git a/test/codegen/maps.go b/test/codegen/maps.go
index dcb4a9381f..ea3a70d1f0 100644
--- a/test/codegen/maps.go
+++ b/test/codegen/maps.go
@@ -122,3 +122,33 @@ func MapClearSideEffect(m map[int]int) int {
}
return k
}
+
+func MapLiteralSizing(x int) (map[int]int, map[int]int) {
+ // amd64:"MOVL\t[$]10,"
+ m := map[int]int{
+ 0: 0,
+ 1: 1,
+ 2: 2,
+ 3: 3,
+ 4: 4,
+ 5: 5,
+ 6: 6,
+ 7: 7,
+ 8: 8,
+ 9: 9,
+ }
+ // amd64:"MOVL\t[$]10,"
+ n := map[int]int{
+ 0: x,
+ 1: x,
+ 2: x,
+ 3: x,
+ 4: x,
+ 5: x,
+ 6: x,
+ 7: x,
+ 8: x,
+ 9: x,
+ }
+ return m, n
+}