Skip to content

Commit a536b72

Browse files
committed
used fixed size for cache allocation
1 parent 1d95b47 commit a536b72

File tree

1 file changed

+2
-10
lines changed

1 file changed

+2
-10
lines changed

parser.go

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -64,10 +64,7 @@ func (c *cache) reset() {
6464
c.vs = c.vs[:0]
6565
}
6666

67-
const (
68-
minPreAllocatedCacheSize = 256
69-
maxPreAllocatedCacheSize = 32768
70-
)
67+
const preAllocatedCacheSize = 32768
7168

7269
func (c *cache) getValue() *Value {
7370
last := len(c.vs) - 1
@@ -77,12 +74,7 @@ func (c *cache) getValue() *Value {
7774
if cap(c.vs) > len(c.vs) {
7875
c.vs = c.vs[:len(c.vs)+1]
7976
} else {
80-
c.allocated++
81-
newSz := minPreAllocatedCacheSize * c.allocated
82-
if newSz > maxPreAllocatedCacheSize {
83-
newSz = maxPreAllocatedCacheSize
84-
}
85-
c.vs = append(c.vs, make([]Value, 0, newSz))
77+
c.vs = append(c.vs, make([]Value, 0, preAllocatedCacheSize))
8678
}
8779
last = len(c.vs) - 1
8880
needExt = false

0 commit comments

Comments
 (0)