From cc47df017da343ee33eee0f4f59974633ca5a486 Mon Sep 17 00:00:00 2001 From: Ian Lance Taylor Date: Fri, 13 Oct 2023 10:34:30 -0700 Subject: runtime: use real type size in map keys and values functions We were using the size stored in the map, which is the smaller of the real type size and 128. As of CL 61538 we don't use these functions, but we expect to use them again in the future after #61626 is resolved. Change-Id: I7bfb4af5f0e3a56361d4019a8ed7c1ec59ff31fd Reviewed-on: https://go-review.googlesource.com/c/go/+/535215 LUCI-TryBot-Result: Go LUCI Reviewed-by: Keith Randall Reviewed-by: Ian Lance Taylor Auto-Submit: Ian Lance Taylor Reviewed-by: Keith Randall --- src/runtime/map_test.go | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) (limited to 'src/runtime/map_test.go') diff --git a/src/runtime/map_test.go b/src/runtime/map_test.go index 7e911b9fc9..2c51236f16 100644 --- a/src/runtime/map_test.go +++ b/src/runtime/map_test.go @@ -1434,3 +1434,33 @@ func TestLoadFactor(t *testing.T) { } } } + +func TestMapKeys(t *testing.T) { + type key struct { + s string + pad [128]byte // sizeof(key) > abi.MapMaxKeyBytes + } + m := map[key]int{{s: "a"}: 1, {s: "b"}: 2} + keys := make([]key, 0, len(m)) + runtime.MapKeys(m, unsafe.Pointer(&keys)) + for _, k := range keys { + if len(k.s) != 1 { + t.Errorf("len(k.s) == %d, want 1", len(k.s)) + } + } +} + +func TestMapValues(t *testing.T) { + type val struct { + s string + pad [128]byte // sizeof(val) > abi.MapMaxElemBytes + } + m := map[int]val{1: {s: "a"}, 2: {s: "b"}} + vals := make([]val, 0, len(m)) + runtime.MapValues(m, unsafe.Pointer(&vals)) + for _, v := range vals { + if len(v.s) != 1 { + t.Errorf("len(v.s) == %d, want 1", len(v.s)) + } + } +} -- cgit v1.3