CL 345486 introduced an optimization to reflect's map accesses
which is not quite correct. We can't use the optimized code if the
value type is >128 bytes.
See cmd/compile/internal/walk/walk.go:mapfast
Fixes #48357
Change-Id: I8e3c7858693083dd4393a8de48ca5fa47bab66f2
Reviewed-on: https://go-review.googlesource.com/c/go/+/349593
Trust: Keith Randall <khr@golang.org>
Trust: Joe Tsai <joetsai@digital-static.net>
Trust: Josh Bleecher Snyder <josharian@gmail.com>
Trust: Martin Möhrmann <martin@golang.org>
Run-TryBot: Keith Randall <khr@golang.org>
Run-TryBot: Joe Tsai <joetsai@digital-static.net>
Reviewed-by: Joe Tsai <joetsai@digital-static.net>
Reviewed-by: Josh Bleecher Snyder <josharian@gmail.com>
Reviewed-by: Martin Möhrmann <martin@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
// of unexported fields.
var e unsafe.Pointer
- if key.kind() == String && tt.key.Kind() == String {
+ if key.kind() == String && tt.key.Kind() == String && tt.elem.size <= maxValSize {
k := *(*string)(key.ptr)
e = mapaccess_faststr(v.typ, v.pointer(), k)
} else {
key.mustBeExported()
tt := (*mapType)(unsafe.Pointer(v.typ))
- if key.kind() == String && tt.key.Kind() == String {
+ if key.kind() == String && tt.key.Kind() == String && tt.elem.size <= maxValSize {
k := *(*string)(key.ptr)
if elem.typ == nil {
mapdelete_faststr(v.typ, v.pointer(), k)
--- /dev/null
+// run
+
+// Copyright 2021 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+package main
+
+import "reflect"
+
+type T [129]byte
+
+func main() {
+ m := map[string]T{}
+ v := reflect.ValueOf(m)
+ v.SetMapIndex(reflect.ValueOf("a"), reflect.ValueOf(T{}))
+ g = m["a"]
+}
+
+var g T