Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

umarshal - refactor skip from recursive calls to a loop. #636

Merged
merged 1 commit into from Oct 11, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
54 changes: 14 additions & 40 deletions plugin/unmarshal/unmarshal.go
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.