Skip to content

Commit

Permalink
opt: enlarge _Threshold_Index and _DEFAULT_NODE_CAP
Browse files Browse the repository at this point in the history
  • Loading branch information
AsterDY committed Jun 30, 2024
1 parent 85e9ef5 commit 4d7daf3
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 6 deletions.
2 changes: 1 addition & 1 deletion ast/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -1766,7 +1766,7 @@ func NewArray(v []Node) Node {
return newArray(s)
}

const _Threshold_Index = _DEFAULT_NODE_CAP
const _Threshold_Index = 16

func newArray(v *linkedNodes) Node {
return Node{
Expand Down
9 changes: 5 additions & 4 deletions ast/node_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"fmt"
"reflect"
"strconv"
"strings"
"testing"

"github.com/bytedance/sonic/internal/native/types"
Expand Down Expand Up @@ -271,7 +272,7 @@ func TestTypeCast(t *testing.T) {
}
var nonEmptyErr error = errors.New("")
a1 := NewAny(1)
lazyArray, _ := NewParser("[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16]").Parse()
lazyArray, _ := NewParser("["+strings.Repeat("1,", _DEFAULT_NODE_CAP)+"1]").Parse()
lazyObject, _ := NewParser(`{"0":0,"1":1,"2":2,"3":3,"4":4,"5":5,"6":6,"7":7,"8":8,"9":9,"10":10,"11":11,"12":12,"13":13,"14":14,"15":15,"16":16}`).Parse()
var cases = []tcase{
{"Interface", Node{}, interface{}(nil), ErrUnsupportType},
Expand Down Expand Up @@ -512,10 +513,10 @@ func TestTypeCast(t *testing.T) {
lazyArray.skipAllIndex()
lazyObject.skipAllKey()
cases = append(cases,
tcase{"Len", lazyArray, 17, nil},
tcase{"Len", lazyArray, _DEFAULT_NODE_CAP+1, nil},
tcase{"Len", lazyObject, 17, nil},
tcase{"Cap", lazyArray, _DEFAULT_NODE_CAP * 3, nil},
tcase{"Cap", lazyObject, _DEFAULT_NODE_CAP * 3, nil},
tcase{"Cap", lazyArray, _DEFAULT_NODE_CAP*2, nil},
tcase{"Cap", lazyObject, _DEFAULT_NODE_CAP, nil},
)

for i, c := range cases {
Expand Down
2 changes: 1 addition & 1 deletion ast/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import (
)

const (
_DEFAULT_NODE_CAP int = 8
_DEFAULT_NODE_CAP int = 64
_APPEND_GROW_SHIFT = 1
)

Expand Down

0 comments on commit 4d7daf3

Please sign in to comment.