Skip to content

Commit c45dae4

Browse files
committed
proto: use UnmarshalState
The UnmarshalState method provides information about whether the message was initialized or not. Checking that bit saves performance needing to verify again. Generated files change because of newer versions of dependencies. Change-Id: I1c1e99b7e28da5959d083ea8652b5fdc8e6c3124 Reviewed-on: https://go-review.googlesource.com/c/protobuf/+/220500 Reviewed-by: Damien Neil <[email protected]>
1 parent 4767034 commit c45dae4

File tree

11 files changed

+17
-110
lines changed

11 files changed

+17
-110
lines changed

go.mod

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@ module github.com/golang/protobuf
33
go 1.9
44

55
require (
6-
github.com/google/go-cmp v0.3.1
7-
google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd
6+
github.com/google/go-cmp v0.4.0
7+
google.golang.org/protobuf v0.0.0-20200221191635-4d8936d0db64
88
)

go.sum

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
1+
github.com/golang/protobuf v1.4.0-rc.1/go.mod h1:ceaxUfeHdC40wWswd/P6IGgMaK3YpKi5j83Wpe3EHw8=
12
github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
2-
github.com/google/go-cmp v0.3.1 h1:Xye71clBPdm5HgqGwUkwhbynsUJZhDbS20FvLhQ2izg=
33
github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
4-
google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd h1:zSMqFwpTkfj+1nNFgmgu4B+Qv5Kpf4jpd11lCmHKuwQ=
4+
github.com/google/go-cmp v0.4.0 h1:xsAVV57WRhGj6kEIi8ReJzQlHHqcBYCElAvkovg3B/4=
5+
github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
6+
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4=
7+
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
58
google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLYBciE7Vtevhsrf46CRTquxDuWsQurQQe4oz8=
9+
google.golang.org/protobuf v0.0.0-20200221191635-4d8936d0db64 h1:BhpvsYSxWvxATQJYrD9UKX1U3jo+Bxq195IzJGtyh40=
10+
google.golang.org/protobuf v0.0.0-20200221191635-4d8936d0db64/go.mod h1:kwYJMbMJ01Woi6D6+Kah6886xMZcty6N08ah7+eCXa0=

proto/wire.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ package proto
66

77
import (
88
protoV2 "google.golang.org/protobuf/proto"
9+
"google.golang.org/protobuf/runtime/protoiface"
910
"google.golang.org/protobuf/runtime/protoimpl"
1011
)
1112

@@ -61,12 +62,17 @@ func Unmarshal(b []byte, m Message) error {
6162
// UnmarshalMerge parses a wire-format message in b and places the decoded results in m.
6263
func UnmarshalMerge(b []byte, m Message) error {
6364
mi := protoimpl.X.ProtoMessageV2Of(m)
64-
err := protoV2.UnmarshalOptions{
65+
out, err := protoV2.UnmarshalOptions{
6566
AllowPartial: true,
6667
Merge: true,
67-
}.Unmarshal(b, mi)
68+
}.UnmarshalState(mi, protoiface.UnmarshalInput{
69+
Buf: b,
70+
})
6871
if err != nil {
6972
return err
7073
}
74+
if out.Flags&protoiface.UnmarshalInitialized > 0 {
75+
return nil
76+
}
7177
return checkRequiredNotSet(mi)
7278
}

protoc-gen-go/descriptor/descriptor.pb.go

Lines changed: 0 additions & 13 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

protoc-gen-go/plugin/plugin.pb.go

Lines changed: 0 additions & 13 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

ptypes/any/any.pb.go

Lines changed: 0 additions & 13 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

ptypes/duration/duration.pb.go

Lines changed: 0 additions & 13 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

ptypes/empty/empty.pb.go

Lines changed: 0 additions & 13 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

ptypes/struct/struct.pb.go

Lines changed: 0 additions & 13 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

ptypes/timestamp/timestamp.pb.go

Lines changed: 0 additions & 13 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)