Skip to content

Commit 1932ccd

Browse files
committed
reuse cache chunks
1 parent 2156dc1 commit 1932ccd

File tree

1 file changed

+24
-13
lines changed

1 file changed

+24
-13
lines changed

parser.go

Lines changed: 24 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -98,21 +98,32 @@ func (c *cache) getValue() *Value {
9898
addNext = true
9999
}
100100
if addNext {
101-
nextSize := len(c.vs)
102-
if nextSize*2 < macAllocatedCacheSize {
103-
nextSize *= 2
104-
} else {
105-
nextSize = macAllocatedCacheSize
106-
}
107-
readSrc = &cache{
108-
vs: make([]Value, 1, nextSize),
109-
}
110-
if c.lt != nil {
111-
c.lt.nx = readSrc
101+
switch {
102+
case c.lt != nil && c.lt.nx != nil:
112103
c.lt = c.lt.nx
113-
} else {
114-
c.nx = readSrc
104+
readSrc = c.lt
105+
readSrc.vs = readSrc.vs[:1]
106+
case c.lt == nil && c.nx != nil:
115107
c.lt = c.nx
108+
readSrc = c.lt
109+
readSrc.vs = readSrc.vs[:1]
110+
default:
111+
nextSize := len(c.vs)
112+
if nextSize*2 < macAllocatedCacheSize {
113+
nextSize *= 2
114+
} else {
115+
nextSize = macAllocatedCacheSize
116+
}
117+
readSrc = &cache{
118+
vs: make([]Value, 1, nextSize),
119+
}
120+
if c.lt != nil {
121+
c.lt.nx = readSrc
122+
c.lt = c.lt.nx
123+
} else {
124+
c.nx = readSrc
125+
c.lt = c.nx
126+
}
116127
}
117128
}
118129
// Do not reset the value, since the caller must properly init it.

0 commit comments

Comments
 (0)