internal/impl: remove unnecessary atomic access for non-lazy lists
Only lazy fields need to be set/read atomically, and the
fieldInfoForMessageListOpaqueNoPresence function is used for non-lazy fields.
(In fact, protoc currently does not allow [lazy = true] on repeated fields.)
I was not able to measure a performance difference either way.
(See Google-internal CL 759558617 for test results.)
Change-Id: Ie4c08a1345b62ecbe0f005d6cc97be35a8fe4daf
Reviewed-on: https://go-review.googlesource.com/c/protobuf/+/674055
Reviewed-by: Lasse Folger <lassefolger@google.com>
Reviewed-by: Damien Neil <dneil@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Cassondra Foesch <cfoesch@gmail.com>
diff --git a/internal/impl/message_opaque.go b/internal/impl/message_opaque.go
index 63a731b..5a439da 100644
--- a/internal/impl/message_opaque.go
+++ b/internal/impl/message_opaque.go
@@ -344,17 +344,15 @@
if p.IsNil() {
return false
}
- sp := p.Apply(fieldOffset).AtomicGetPointer()
- if sp.IsNil() {
+ rv := p.Apply(fieldOffset).AsValueOf(fs.Type).Elem()
+ if rv.IsNil() {
return false
}
- rv := sp.AsValueOf(fs.Type.Elem())
return rv.Elem().Len() > 0
},
clear: func(p pointer) {
- sp := p.Apply(fieldOffset).AtomicGetPointer()
- if !sp.IsNil() {
- rv := sp.AsValueOf(fs.Type.Elem())
+ rv := p.Apply(fieldOffset).AsValueOf(fs.Type).Elem()
+ if !rv.IsNil() {
rv.Elem().Set(reflect.Zero(rv.Type().Elem()))
}
},
@@ -362,11 +360,10 @@
if p.IsNil() {
return conv.Zero()
}
- sp := p.Apply(fieldOffset).AtomicGetPointer()
- if sp.IsNil() {
+ rv := p.Apply(fieldOffset).AsValueOf(fs.Type).Elem()
+ if rv.IsNil() {
return conv.Zero()
}
- rv := sp.AsValueOf(fs.Type.Elem())
if rv.Elem().Len() == 0 {
return conv.Zero()
}