Skip to content

Commit

Permalink
umarshal - refactor skip from recursive calls to a loop. (#636)
Browse files Browse the repository at this point in the history
  • Loading branch information
jmarais authored Oct 11, 2019
1 parent 69adf3e commit 627c0c9
Show file tree
Hide file tree
Showing 74 changed files with 1,182 additions and 3,106 deletions.
54 changes: 14 additions & 40 deletions plugin/unmarshal/unmarshal.go
Original file line number Diff line number Diff line change
Expand Up @@ -1578,6 +1578,7 @@ func (p *unmarshal) Generate(file *generator.FileDescriptor) {
p.P(`func skip` + p.localName + `(dAtA []byte) (n int, err error) {
l := len(dAtA)
iNdEx := 0
depth := 0
for iNdEx < l {
var wire uint64
for shift := uint(0); ; shift += 7 {
Expand Down Expand Up @@ -1609,10 +1610,8 @@ func (p *unmarshal) Generate(file *generator.FileDescriptor) {
break
}
}
return iNdEx, nil
case 1:
iNdEx += 8
return iNdEx, nil
case 2:
var length int
for shift := uint(0); ; shift += 7 {
Expand All @@ -1633,57 +1632,32 @@ func (p *unmarshal) Generate(file *generator.FileDescriptor) {
return 0, ErrInvalidLength` + p.localName + `
}
iNdEx += length
if iNdEx < 0 {
return 0, ErrInvalidLength` + p.localName + `
}
return iNdEx, nil
case 3:
for {
var innerWire uint64
var start int = iNdEx
for shift := uint(0); ; shift += 7 {
if shift >= 64 {
return 0, ErrIntOverflow` + p.localName + `
}
if iNdEx >= l {
return 0, ` + p.ioPkg.Use() + `.ErrUnexpectedEOF
}
b := dAtA[iNdEx]
iNdEx++
innerWire |= (uint64(b) & 0x7F) << shift
if b < 0x80 {
break
}
}
innerWireType := int(innerWire & 0x7)
if innerWireType == 4 {
break
}
next, err := skip` + p.localName + `(dAtA[start:])
if err != nil {
return 0, err
}
iNdEx = start + next
if iNdEx < 0 {
return 0, ErrInvalidLength` + p.localName + `
}
}
return iNdEx, nil
depth++
case 4:
return iNdEx, nil
if depth == 0 {
return 0, ErrUnexpectedEndOfGroup` + p.localName + `
}
depth--
case 5:
iNdEx += 4
return iNdEx, nil
default:
return 0, ` + fmtPkg.Use() + `.Errorf("proto: illegal wireType %d", wireType)
}
if iNdEx < 0 {
return 0, ErrInvalidLength` + p.localName + `
}
if depth == 0 {
return iNdEx, nil
}
}
panic("unreachable")
return 0, ` + p.ioPkg.Use() + `.ErrUnexpectedEOF
}
var (
ErrInvalidLength` + p.localName + ` = ` + fmtPkg.Use() + `.Errorf("proto: negative length found during unmarshaling")
ErrIntOverflow` + p.localName + ` = ` + fmtPkg.Use() + `.Errorf("proto: integer overflow")
ErrUnexpectedEndOfGroup` + p.localName + ` = ` + fmtPkg.Use() + `.Errorf("proto: unexpected end of group")
)
`)
}
Expand Down
58 changes: 16 additions & 42 deletions test/asymetric-issue125/asym.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

58 changes: 16 additions & 42 deletions test/casttype/combos/both/casttype.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

58 changes: 16 additions & 42 deletions test/casttype/combos/unmarshaler/casttype.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 627c0c9

Please sign in to comment.