1
1
mirror of https://github.com/wader/fq.git synced 2024-12-23 05:13:30 +03:00

decode: improve stack push/pop

This commit is contained in:
David McDonald 2022-12-03 15:27:59 -06:00
parent 62f377c2fe
commit b45f9fa67b

View File

@ -327,7 +327,7 @@ type stack []int64
var offsetStack stack
func (s *stack) tryPush(d *decode.D) {
func (s *stack) pushAndPop(d *decode.D) func() {
i := d.Pos()
for _, o := range offsetStack {
if i == o {
@ -335,6 +335,7 @@ func (s *stack) tryPush(d *decode.D) {
}
}
*s = append(*s, i)
return s.pop
}
func (s *stack) pop() {
@ -342,7 +343,7 @@ func (s *stack) pop() {
}
func decodeRecord(d *decode.D) {
offsetStack.tryPush(d)
defer offsetStack.pushAndPop(d)()
d.FieldStruct("record", func(d *decode.D) {
n := int(d.FieldU32("length"))
@ -402,7 +403,6 @@ func decodeRecord(d *decode.D) {
})
}
})
offsetStack.pop()
}
const reservedSize = 32