aboutsummaryrefslogtreecommitdiff
path: root/src/reflect/value.go
diff options
context:
space:
mode:
authorKeith Randall <khr@golang.org>2021-09-13 09:17:22 -0700
committerKeith Randall <khr@golang.org>2021-09-13 18:38:15 +0000
commitac40c9872f6e8ef095dcc6ee556236782eee4f76 (patch)
treefc3e6168541f973c796be3deb83a4ba9eceee31b /src/reflect/value.go
parentc8a58f29dcb2b4f38ca4fcf4d2a2a80f606c9573 (diff)
downloadgo-ac40c9872f6e8ef095dcc6ee556236782eee4f76.tar.gz
go-ac40c9872f6e8ef095dcc6ee556236782eee4f76.zip
reflect: fix _faststr optimization
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>
Diffstat (limited to 'src/reflect/value.go')
-rw-r--r--src/reflect/value.go4
1 files changed, 2 insertions, 2 deletions
diff --git a/src/reflect/value.go b/src/reflect/value.go
index 6e9aaabe8a..bc48a76ce6 100644
--- a/src/reflect/value.go
+++ b/src/reflect/value.go
@@ -1517,7 +1517,7 @@ func (v Value) MapIndex(key Value) Value {
// 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 {
@@ -2128,7 +2128,7 @@ func (v Value) SetMapIndex(key, elem Value) {
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)