1
0
mirror of https://github.com/golang/go synced 2024-11-17 10:14:46 -07:00

reflect: delete TODO pass safe to packEface don't need to copy if safe==true

valueInterface not copy result in the follow incorrect behavior
w1.  x := ValueOf(&v).Elem()
r1.  iface := Value.Interface()
w2.  x.Set() or x.SetT()

The write operation of W2 will be observed by the read operation of r1,
but the existing behavior is not.

The valueInterface in deepValueEqual can, in theory, pass safe==true to not copy the object,
but there is no benchmark to indicate that the memory allocation has changed,
maybe we don't actually need safe==true here.

Change-Id: I55c423fd50adac8822a7fdbfe67af89ee223eace
GitHub-Last-Rev: 4a63867098
GitHub-Pull-Request: golang/go#64618
Reviewed-on: https://go-review.googlesource.com/c/go/+/548436
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Cherry Mui <cherryyz@google.com>
Reviewed-by: Keith Randall <khr@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Keith Randall <khr@golang.org>
Auto-Submit: Keith Randall <khr@golang.org>
This commit is contained in:
qiulaidongfeng 2024-01-23 00:42:58 +00:00 committed by Gopher Robot
parent f75e1c1460
commit 8c45dddd5d

View File

@ -129,8 +129,6 @@ func packEface(v Value) any {
// Value is indirect, and so is the interface we're making.
ptr := v.ptr
if v.flag&flagAddr != 0 {
// TODO: pass safe boolean from valueInterface so
// we don't need to copy if safe==true?
c := unsafe_New(t)
typedmemmove(t, c, ptr)
ptr = c
@ -1522,7 +1520,6 @@ func valueInterface(v Value, safe bool) any {
})(v.ptr)
}
// TODO: pass safe to packEface so we don't need to copy if safe==true?
return packEface(v)
}