Skip to content

Commit 32018e9

Browse files
committed
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 <[email protected]> Reviewed-by: Damien Neil <[email protected]> LUCI-TryBot-Result: Go LUCI <[email protected]> Reviewed-by: Cassondra Foesch <[email protected]>
1 parent 9c38aec commit 32018e9

File tree

1 file changed

+6
-9
lines changed

1 file changed

+6
-9
lines changed

internal/impl/message_opaque.go

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -344,29 +344,26 @@ func (mi *MessageInfo) fieldInfoForMessageListOpaqueNoPresence(si opaqueStructIn
344344
if p.IsNil() {
345345
return false
346346
}
347-
sp := p.Apply(fieldOffset).AtomicGetPointer()
348-
if sp.IsNil() {
347+
rv := p.Apply(fieldOffset).AsValueOf(fs.Type).Elem()
348+
if rv.IsNil() {
349349
return false
350350
}
351-
rv := sp.AsValueOf(fs.Type.Elem())
352351
return rv.Elem().Len() > 0
353352
},
354353
clear: func(p pointer) {
355-
sp := p.Apply(fieldOffset).AtomicGetPointer()
356-
if !sp.IsNil() {
357-
rv := sp.AsValueOf(fs.Type.Elem())
354+
rv := p.Apply(fieldOffset).AsValueOf(fs.Type).Elem()
355+
if !rv.IsNil() {
358356
rv.Elem().Set(reflect.Zero(rv.Type().Elem()))
359357
}
360358
},
361359
get: func(p pointer) protoreflect.Value {
362360
if p.IsNil() {
363361
return conv.Zero()
364362
}
365-
sp := p.Apply(fieldOffset).AtomicGetPointer()
366-
if sp.IsNil() {
363+
rv := p.Apply(fieldOffset).AsValueOf(fs.Type).Elem()
364+
if rv.IsNil() {
367365
return conv.Zero()
368366
}
369-
rv := sp.AsValueOf(fs.Type.Elem())
370367
if rv.Elem().Len() == 0 {
371368
return conv.Zero()
372369
}

0 commit comments

Comments
 (0)