File tree Expand file tree Collapse file tree 1 file changed +24
-7
lines changed Expand file tree Collapse file tree 1 file changed +24
-7
lines changed Original file line number Diff line number Diff line change @@ -53,21 +53,38 @@ func (p *Parser) ParseBytes(b []byte) (*Value, error) {
53
53
}
54
54
55
55
type cache struct {
56
- vs []Value
56
+ vs [][] Value
57
57
}
58
58
59
59
func (c * cache ) reset () {
60
+ for i := range c .vs {
61
+ c .vs [i ] = c .vs [i ][:0 ]
62
+ }
60
63
c .vs = c .vs [:0 ]
61
64
}
62
65
63
66
func (c * cache ) getValue () * Value {
64
- if cap (c .vs ) > len (c .vs ) {
65
- c .vs = c .vs [:len (c .vs )+ 1 ]
66
- } else {
67
- c .vs = append (c .vs , Value {})
67
+ l := len (c .vs ) - 1
68
+ needExt := l < 0 || cap (c .vs [l ]) == len (c .vs [l ])
69
+ for {
70
+ if needExt {
71
+ if cap (c .vs ) > len (c .vs ) {
72
+ c .vs = c .vs [:len (c .vs )+ 1 ]
73
+ } else {
74
+ c .vs = append (c .vs , make ([]Value , 0 , 32768 ))
75
+ }
76
+ l = len (c .vs ) - 1
77
+ needExt = false
78
+ }
79
+ if cap (c .vs [l ]) > len (c .vs [l ]) {
80
+ c .vs [l ] = c .vs [l ][:len (c .vs [l ])+ 1 ]
81
+ } else {
82
+ needExt = true
83
+ continue
84
+ }
85
+ // Do not reset the value, since the caller must properly init it.
86
+ return & c .vs [l ][len (c .vs [l ])- 1 ]
68
87
}
69
- // Do not reset the value, since the caller must properly init it.
70
- return & c .vs [len (c .vs )- 1 ]
71
88
}
72
89
73
90
func skipWS (s string ) string {
You can’t perform that action at this time.
0 commit comments