Explorar el Código

internal/proto: use protoregistry.Files.FindFileByPath

CL/182497 adds this new API.

Change-Id: I14498a3b4ef295e8c9512e1a2ec10553915c7a92
Reviewed-on: https://go-review.googlesource.com/c/protobuf/+/182517
Reviewed-by: Damien Neil <dneil@google.com>
Joe Tsai hace 6 años
padre
commit
f94016f523
Se han modificado 3 ficheros con 4 adiciones y 12 borrados
  1. 1 1
      go.mod
  2. 2 2
      go.sum
  3. 1 9
      internal/proto/registry.go

+ 1 - 1
go.mod

@@ -2,4 +2,4 @@ module github.com/golang/protobuf
 
 
 go 1.9
 go 1.9
 
 
-require google.golang.org/protobuf v0.0.0-20190617173324-378c1329ded0
+require google.golang.org/protobuf v0.0.0-20190617175724-bd7b7a9e0c26

+ 2 - 2
go.sum

@@ -12,5 +12,5 @@ google.golang.org/protobuf v0.0.0-20190516201745-40b83d67fc75/go.mod h1:jf+u8AHu
 google.golang.org/protobuf v0.0.0-20190516215540-a95b29fbf623/go.mod h1:cWWmz5lsCWIcqGLROrKq5Lu231IJw2PzqOZ8cgspbfY=
 google.golang.org/protobuf v0.0.0-20190516215540-a95b29fbf623/go.mod h1:cWWmz5lsCWIcqGLROrKq5Lu231IJw2PzqOZ8cgspbfY=
 google.golang.org/protobuf v0.0.0-20190522194032-21ade498bd69/go.mod h1:cJytyYi/6qdwy/+gD49hmgHcwD7zhWxE/1KPEslaZ3M=
 google.golang.org/protobuf v0.0.0-20190522194032-21ade498bd69/go.mod h1:cJytyYi/6qdwy/+gD49hmgHcwD7zhWxE/1KPEslaZ3M=
 google.golang.org/protobuf v0.0.0-20190605195314-89d49632e5cf/go.mod h1:Btug4TBaP5wNYcb2zGKDTS7WMcaPPLuqEAKfEAZWYbo=
 google.golang.org/protobuf v0.0.0-20190605195314-89d49632e5cf/go.mod h1:Btug4TBaP5wNYcb2zGKDTS7WMcaPPLuqEAKfEAZWYbo=
-google.golang.org/protobuf v0.0.0-20190617173324-378c1329ded0 h1:xWgajdfLzmZPasRoZwpEGv4W/ouKCE33vYT9lIhwXTI=
-google.golang.org/protobuf v0.0.0-20190617173324-378c1329ded0/go.mod h1:+FOB8T5/Yw4ywwdyeun9/KlDeuwFYBkNQ+kVuwj9C94=
+google.golang.org/protobuf v0.0.0-20190617175724-bd7b7a9e0c26 h1:TNW9FO1kBCrRCRWMg37SPUITvx76qDVlAja8TSVvX4c=
+google.golang.org/protobuf v0.0.0-20190617175724-bd7b7a9e0c26/go.mod h1:+FOB8T5/Yw4ywwdyeun9/KlDeuwFYBkNQ+kVuwj9C94=

+ 1 - 9
internal/proto/registry.go

@@ -78,11 +78,7 @@ func FileDescriptor(s filePath) (d fileDescGZIP) {
 	}
 	}
 
 
 	// Find the descriptor in the v2 registry.
 	// Find the descriptor in the v2 registry.
-	var n int
-	protoregistry.GlobalFiles.RangeFilesByPath(s, func(fd pref.FileDescriptor) bool {
-		n++
-
-		// Convert the structured file descriptor to the raw descriptor proto.
+	if fd, _ := protoregistry.GlobalFiles.FindFileByPath(s); fd != nil {
 		pb := protodesc.ToFileDescriptorProto(fd)
 		pb := protodesc.ToFileDescriptorProto(fd)
 		b, err := protoV2.Marshal(pb)
 		b, err := protoV2.Marshal(pb)
 		if err != nil {
 		if err != nil {
@@ -97,10 +93,6 @@ func FileDescriptor(s filePath) (d fileDescGZIP) {
 			panic(fmt.Sprintf("proto: compression failure: %v", err))
 			panic(fmt.Sprintf("proto: compression failure: %v", err))
 		}
 		}
 		d = bb.Bytes()
 		d = bb.Bytes()
-		return true
-	})
-	if n > 1 {
-		return d // best-effort; may be non-deterministic
 	}
 	}
 
 
 	// Locally cache the raw descriptor form for the file.
 	// Locally cache the raw descriptor form for the file.