internal/impl: add fast-path for IsInitialized
This currently returns uninformative errors from the fast path and then
consults the slow, reflection-based path only when an error is detected.
Perhaps it's worth going through the effort of producing better errors
directly on the fast path.
Change-Id: I68536e9438010dbd97dbaff4f47b78430221d94b
Reviewed-on: https://go-review.googlesource.com/c/protobuf/+/171462
Reviewed-by: Joe Tsai <thebrokentoaster@gmail.com>
diff --git a/internal/impl/message.go b/internal/impl/message.go
index 161f194..7c4873a 100644
--- a/internal/impl/message.go
+++ b/internal/impl/message.go
@@ -47,6 +47,7 @@
methods piface.Methods
+ needsInitCheck bool
sizecacheOffset offset
extensionOffset offset
unknownOffset offset
@@ -101,6 +102,7 @@
}
si := mi.makeStructInfo(t.Elem())
+ mi.needsInitCheck = needsInitCheck(mi.PBType)
mi.makeKnownFieldsFunc(si)
mi.makeUnknownFieldsFunc(t.Elem())
mi.makeExtensionFieldsFunc(t.Elem())
@@ -139,6 +141,7 @@
mi.methods.Flags = piface.MethodFlagDeterministicMarshal
mi.methods.MarshalAppend = mi.marshalAppend
mi.methods.Size = mi.size
+ mi.methods.IsInitialized = mi.isInitialized
}
type structInfo struct {