Skip to content

Commit

Permalink
BAAS-26274: Increase int cache size to 16384 (#106)
Browse files Browse the repository at this point in the history
  • Loading branch information
Calvinnix authored Nov 14, 2023
1 parent ca84fd0 commit e553922
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
6 changes: 4 additions & 2 deletions value.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,9 @@ var (
reflectTypeError = reflect.TypeOf((*error)(nil)).Elem()
)

var intCache [256]Value
const intCacheSize = 16384

var intCache [intCacheSize]Value
var int64Cache [256]Value

func FalseValue() Value {
Expand Down Expand Up @@ -1710,7 +1712,7 @@ func typeErrorResult(throw bool, args ...interface{}) {
}

func init() {
for i := 0; i < 256; i++ {
for i := 0; i < intCacheSize; i++ {
intCache[i] = valueInt(i - 128)
}
for i := 0; i < 256; i++ {
Expand Down
2 changes: 1 addition & 1 deletion vm.go
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@ func (vm *vm) setFuncName(s unistring.String) {

func intToValue(i int64) Value {
if i >= -maxInt && i <= maxInt {
if i >= -128 && i <= 127 {
if i >= -128 && i <= (intCacheSize-129) {
return intCache[i+128]
}
return valueInt(i)
Expand Down

0 comments on commit e553922

Please sign in to comment.