File tree Expand file tree Collapse file tree 1 file changed +12
-3
lines changed Expand file tree Collapse file tree 1 file changed +12
-3
lines changed Original file line number Diff line number Diff line change @@ -53,7 +53,8 @@ func (p *Parser) ParseBytes(b []byte) (*Value, error) {
53
53
}
54
54
55
55
type cache struct {
56
- vs [][]Value
56
+ vs [][]Value
57
+ allocated int
57
58
}
58
59
59
60
func (c * cache ) reset () {
@@ -63,7 +64,10 @@ func (c *cache) reset() {
63
64
c .vs = c .vs [:0 ]
64
65
}
65
66
66
- const preAllocatedCacheSize = 409 // calculated as 32768 / unsafe.SizeOf(Value)
67
+ const (
68
+ minPreAllocatedCacheSize = 256
69
+ maxPreAllocatedCacheSize = 32768
70
+ )
67
71
68
72
func (c * cache ) getValue () * Value {
69
73
last := len (c .vs ) - 1
@@ -73,7 +77,12 @@ func (c *cache) getValue() *Value {
73
77
if cap (c .vs ) > len (c .vs ) {
74
78
c .vs = c .vs [:len (c .vs )+ 1 ]
75
79
} else {
76
- c .vs = append (c .vs , make ([]Value , 0 , preAllocatedCacheSize ))
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
86
}
78
87
last = len (c .vs ) - 1
79
88
needExt = false
You can’t perform that action at this time.
0 commit comments