File tree Expand file tree Collapse file tree 1 file changed +9
-7
lines changed Expand file tree Collapse file tree 1 file changed +9
-7
lines changed Original file line number Diff line number Diff line change @@ -63,27 +63,29 @@ func (c *cache) reset() {
63
63
c .vs = c .vs [:0 ]
64
64
}
65
65
66
+ const preAllocatedCacheSize = 409 // calculated as 32768 / unsafe.SizeOf(Value)
67
+
66
68
func (c * cache ) getValue () * Value {
67
- l := len (c .vs ) - 1
68
- needExt := l < 0 || cap (c .vs [l ]) == len (c .vs [l ])
69
+ last := len (c .vs ) - 1
70
+ needExt := last < 0 || cap (c .vs [last ]) == len (c .vs [last ])
69
71
for {
70
72
if needExt {
71
73
if cap (c .vs ) > len (c .vs ) {
72
74
c .vs = c .vs [:len (c .vs )+ 1 ]
73
75
} else {
74
- c .vs = append (c .vs , make ([]Value , 0 , 32768 ))
76
+ c .vs = append (c .vs , make ([]Value , 0 , preAllocatedCacheSize ))
75
77
}
76
- l = len (c .vs ) - 1
78
+ last = len (c .vs ) - 1
77
79
needExt = false
78
80
}
79
- if cap (c .vs [l ]) > len (c .vs [l ]) {
80
- c .vs [l ] = c .vs [l ][:len (c .vs [l ])+ 1 ]
81
+ if cap (c .vs [last ]) > len (c .vs [last ]) {
82
+ c .vs [last ] = c .vs [last ][:len (c .vs [last ])+ 1 ]
81
83
} else {
82
84
needExt = true
83
85
continue
84
86
}
85
87
// Do not reset the value, since the caller must properly init it.
86
- return & c .vs [l ][len (c .vs [l ])- 1 ]
88
+ return & c .vs [last ][len (c .vs [last ])- 1 ]
87
89
}
88
90
}
89
91
You can’t perform that action at this time.
0 commit comments