Skip to content

Commit

Permalink
bench ast.Node.GetByPath()
Browse files Browse the repository at this point in the history
  • Loading branch information
AsterDY committed Jun 20, 2024
1 parent 5371c86 commit 0b4bcb9
Showing 1 changed file with 16 additions and 7 deletions.
23 changes: 16 additions & 7 deletions ast/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,16 @@
package ast

import (
`encoding/json`
`fmt`
`strconv`
`unsafe`

`github.com/bytedance/sonic/internal/native/types`
`github.com/bytedance/sonic/internal/rt`
"encoding/json"
"fmt"
"strconv"
"sync"

// "sync"
"unsafe"

"github.com/bytedance/sonic/internal/native/types"
"github.com/bytedance/sonic/internal/rt"
)

const (
Expand Down Expand Up @@ -56,6 +59,8 @@ type Node struct {
t types.ValueType
l uint
p unsafe.Pointer
safe bool
m sync.RWMutex
}

// UnmarshalJSON is just an adapter to json.Unmarshaler.
Expand Down Expand Up @@ -787,6 +792,10 @@ func (self *Node) AddAny(val interface{}) error {
// Note, the api expects the json is well-formed at least,
// otherwise it may return unexpected result.
func (self *Node) GetByPath(path ...interface{}) *Node {
if self.safe {
self.m.RLock()
defer self.m.RUnlock()
}
if !self.Valid() {
return self
}
Expand Down

0 comments on commit 0b4bcb9

Please sign in to comment.