Upstream itchyny/gojq state of the touched files before f68bda411a
This commit is contained in:
1 parent
a7ed5ccbe9
commit
b18851b748
3 files changed
+35
-128
No files matched your search
@@ -14,6 +14,7 @@ import (
|
||||
"reflect"
|
||||
"regexp"
|
||||
"slices"
|
||||
"sort"
|
||||
"strconv"
|
||||
"strings"
|
||||
"sync"
|
||||
@@ -437,7 +438,9 @@ func add(xs iter.Seq[any]) any {
|
||||
case []any:
|
||||
switch w := v.(type) {
|
||||
case nil:
|
||||
v = slices.Clone(x)
|
||||
s := make([]any, len(x))
|
||||
copy(s, x)
|
||||
v = s
|
||||
continue
|
||||
case []any:
|
||||
v = append(w, x...)
|
||||
@@ -766,13 +769,6 @@ func funcSplit(v, x any) any {
|
||||
if !ok {
|
||||
return &func0TypeError{"split", x}
|
||||
}
|
||||
return splitString(s, t)
|
||||
}
|
||||
|
||||
func splitString(s, t string) []any {
|
||||
if s == "" {
|
||||
return []any{}
|
||||
}
|
||||
ss := strings.Split(s, t)
|
||||
xs := make([]any, len(ss))
|
||||
for i, s := range ss {
|
||||
@@ -1488,17 +1484,6 @@ func (a allocator) allocated(v any) bool {
|
||||
return ok
|
||||
}
|
||||
|
||||
// release forgets every allocated address when the value is one of them, so
|
||||
// that a value handed to a query is copied on update again.
|
||||
func (a allocator) release(v any) {
|
||||
switch v.(type) {
|
||||
case map[string]any, []any:
|
||||
if a.allocated(v) {
|
||||
clear(a)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (a allocator) makeObject(l int) map[string]any {
|
||||
v := make(map[string]any, l)
|
||||
if a != nil {
|
||||
@@ -1525,15 +1510,6 @@ func funcSetpathWithAllocator(v any, args []any) any {
|
||||
return setpath(v, args[0], args[1], args[2].(allocator))
|
||||
}
|
||||
|
||||
// Used in compiler#compileModify: the update function may store the value
|
||||
// anywhere, so it must not be modified in place afterwards. Registered as
|
||||
// getpath to keep tracking paths through the call.
|
||||
func funcGetpathWithAllocator(v any, args []any) any {
|
||||
w := funcGetpath(v, args[0])
|
||||
args[1].(allocator).release(w)
|
||||
return w
|
||||
}
|
||||
|
||||
func setpath(v, p, n any, a allocator) any {
|
||||
path, ok := p.([]any)
|
||||
if !ok {
|
||||
@@ -1611,8 +1587,6 @@ func update(v any, path []any, n any, a allocator) (any, error) {
|
||||
return nil, &expectedArrayError{v}
|
||||
}
|
||||
case map[string]any:
|
||||
// A slice bound stays reachable through the path.
|
||||
a.release(p)
|
||||
switch v := v.(type) {
|
||||
case nil:
|
||||
return updateArraySlice(nil, p, path[1:], n, a)
|
||||
@@ -1805,9 +1779,14 @@ func funcGetpath(v, p any) any {
|
||||
}
|
||||
u := v
|
||||
for _, x := range path {
|
||||
v = funcIndex2(nil, v, x)
|
||||
if err, ok := v.(error); ok {
|
||||
return &func1WrapError{"getpath", u, p, err}
|
||||
switch v.(type) {
|
||||
case nil, []any, map[string]any:
|
||||
v = funcIndex2(nil, v, x)
|
||||
if err, ok := v.(error); ok {
|
||||
return &func1WrapError{"getpath", u, p, err}
|
||||
}
|
||||
default:
|
||||
return &func1TypeError{"getpath", u, p}
|
||||
}
|
||||
}
|
||||
return v
|
||||
@@ -1851,8 +1830,10 @@ func funcBsearch(v, t any) any {
|
||||
if !ok {
|
||||
return &func1TypeError{"bsearch", v, t}
|
||||
}
|
||||
i, ok := slices.BinarySearchFunc(vs, t, Compare)
|
||||
if ok {
|
||||
i := sort.Search(len(vs), func(i int) bool {
|
||||
return Compare(vs[i], t) >= 0
|
||||
})
|
||||
if i < len(vs) && Compare(vs[i], t) == 0 {
|
||||
return i
|
||||
}
|
||||
return -i - 1
|
||||
|
||||
Reference in new issue
Block a user