all: do best-effort initialization check on fast path unmarshal
Add a fast check for required fields to the fast path unmarshal.
This is best-effort and will fail to detect some initialized
messages: Messages with more than 64 required fields, messages
split across multiple tags, possibly other cases.
In the cases where it works (which is most of them in practice),
this permits us to skip the IsInitialized check.
Change-Id: I6b70953a333033a5e64fb7ca37a59786cb0f75a0
Reviewed-on: https://go-review.googlesource.com/c/protobuf/+/215878
Reviewed-by: Joe Tsai <joetsai@google.com>
diff --git a/internal/impl/codec_map.go b/internal/impl/codec_map.go
index b69ee1a..c8c0925 100644
--- a/internal/impl/codec_map.go
+++ b/internal/impl/codec_map.go
@@ -202,7 +202,13 @@
if n < 0 {
return out, wire.ParseError(n)
}
- _, err = mapi.valMessageInfo.unmarshalPointer(v, pointerOfValue(val), 0, opts)
+ var o unmarshalOutput
+ o, err = mapi.valMessageInfo.unmarshalPointer(v, pointerOfValue(val), 0, opts)
+ if o.initialized {
+ // Consider this map item initialized so long as we see
+ // an initialized value.
+ out.initialized = true
+ }
}
if err == errUnknown {
n = wire.ConsumeFieldValue(num, wtyp, b)