diff options
author | 2024-08-19 10:13:46 +0000 | |
---|---|---|
committer | 2024-08-19 10:13:46 +0000 | |
commit | 6ff8376d96f094daacf62decf2ee7ff602c2d531 (patch) | |
tree | 0b0ad45951ef1aae841384fd550e01b44f4cba76 /vendor/google.golang.org/protobuf/internal/impl/codec_extension.go | |
parent | [bugfix] permit unspecified orientation data (#3205) (diff) | |
download | gotosocial-6ff8376d96f094daacf62decf2ee7ff602c2d531.tar.xz |
[chore]: Bump github.com/prometheus/client_golang from 1.19.1 to 1.20.0 (#3210)
Diffstat (limited to 'vendor/google.golang.org/protobuf/internal/impl/codec_extension.go')
-rw-r--r-- | vendor/google.golang.org/protobuf/internal/impl/codec_extension.go | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/vendor/google.golang.org/protobuf/internal/impl/codec_extension.go b/vendor/google.golang.org/protobuf/internal/impl/codec_extension.go index 2b8f122c2..4bb0a7a20 100644 --- a/vendor/google.golang.org/protobuf/internal/impl/codec_extension.go +++ b/vendor/google.golang.org/protobuf/internal/impl/codec_extension.go @@ -99,6 +99,28 @@ func (f *ExtensionField) canLazy(xt protoreflect.ExtensionType) bool { return false } +// isUnexpandedLazy returns true if the ExensionField is lazy and not +// yet expanded, which means it's present and already checked for +// initialized required fields. +func (f *ExtensionField) isUnexpandedLazy() bool { + return f.lazy != nil && atomic.LoadUint32(&f.lazy.atomicOnce) == 0 +} + +// lazyBuffer retrieves the buffer for a lazy extension if it's not yet expanded. +// +// The returned buffer has to be kept over whatever operation we're planning, +// as re-retrieving it will fail after the message is lazily decoded. +func (f *ExtensionField) lazyBuffer() []byte { + // This function might be in the critical path, so check the atomic without + // taking a look first, then only take the lock if needed. + if !f.isUnexpandedLazy() { + return nil + } + f.lazy.mu.Lock() + defer f.lazy.mu.Unlock() + return f.lazy.b +} + func (f *ExtensionField) lazyInit() { f.lazy.mu.Lock() defer f.lazy.mu.Unlock() |