Upstream itchyny/gojq state of the touched files before 326d9db5da

This commit is contained in:
upstream committed 2026-09-13 23:22:06 +02:00
1 parent 70b3f7d698
commit 096ffac211
1 file changed
+19 -26
+19 -26
View File
@@ -14,7 +14,6 @@ import (
"reflect" "reflect"
"regexp" "regexp"
"slices" "slices"
"sort"
"strconv" "strconv"
"strings" "strings"
"sync" "sync"
@@ -438,9 +437,7 @@ func add(xs iter.Seq[any]) any {
case []any: case []any:
switch w := v.(type) { switch w := v.(type) {
case nil: case nil:
s := make([]any, len(x)) v = slices.Clone(x)
copy(s, x)
v = s
continue continue
case []any: case []any:
v = append(w, x...) v = append(w, x...)
@@ -769,6 +766,13 @@ func funcSplit(v, x any) any {
if !ok { if !ok {
return &func0TypeError{"split", x} return &func0TypeError{"split", x}
} }
return splitString(s, t)
}
func splitString(s, t string) []any {
if s == "" {
return []any{}
}
ss := strings.Split(s, t) ss := strings.Split(s, t)
xs := make([]any, len(ss)) xs := make([]any, len(ss))
for i, s := range ss { for i, s := range ss {
@@ -1484,10 +1488,8 @@ func (a allocator) allocated(v any) bool {
return ok return ok
} }
// release forgets every allocated address when the value is one of them. It is // release forgets every allocated address when the value is one of them, so
// called wherever a value the allocator created is handed to a query, which // that a value handed to a query is copied on update again.
// may keep any number of references to it; from that point on the values are
// copied on update again, as if they had been allocated elsewhere.
func (a allocator) release(v any) { func (a allocator) release(v any) {
switch v.(type) { switch v.(type) {
case map[string]any, []any: case map[string]any, []any:
@@ -1523,10 +1525,9 @@ func funcSetpathWithAllocator(v any, args []any) any {
return setpath(v, args[0], args[1], args[2].(allocator)) return setpath(v, args[0], args[1], args[2].(allocator))
} }
// Used in compiler#compileModify. The value at the path is passed to the // Used in compiler#compileModify: the update function may store the value
// update function, which may store it in any number of places, so it must not // anywhere, so it must not be modified in place afterwards. Registered as
// be modified in place afterwards. It is registered under the name of getpath // getpath to keep tracking paths through the call.
// to keep tracking paths through the call.
func funcGetpathWithAllocator(v any, args []any) any { func funcGetpathWithAllocator(v any, args []any) any {
w := funcGetpath(v, args[0]) w := funcGetpath(v, args[0])
args[1].(allocator).release(w) args[1].(allocator).release(w)
@@ -1610,8 +1611,7 @@ func update(v any, path []any, n any, a allocator) (any, error) {
return nil, &expectedArrayError{v} return nil, &expectedArrayError{v}
} }
case map[string]any: case map[string]any:
// A path element is an object only when slicing an array, and it stays // A slice bound stays reachable through the path.
// reachable through the path, so it must not be modified in place.
a.release(p) a.release(p)
switch v := v.(type) { switch v := v.(type) {
case nil: case nil:
@@ -1805,14 +1805,9 @@ func funcGetpath(v, p any) any {
} }
u := v u := v
for _, x := range path { for _, x := range path {
switch v.(type) { v = funcIndex2(nil, v, x)
case nil, []any, map[string]any: if err, ok := v.(error); ok {
v = funcIndex2(nil, v, x) return &func1WrapError{"getpath", u, p, err}
if err, ok := v.(error); ok {
return &func1WrapError{"getpath", u, p, err}
}
default:
return &func1TypeError{"getpath", u, p}
} }
} }
return v return v
@@ -1856,10 +1851,8 @@ func funcBsearch(v, t any) any {
if !ok { if !ok {
return &func1TypeError{"bsearch", v, t} return &func1TypeError{"bsearch", v, t}
} }
i := sort.Search(len(vs), func(i int) bool { i, ok := slices.BinarySearchFunc(vs, t, Compare)
return Compare(vs[i], t) >= 0 if ok {
})
if i < len(vs) && Compare(vs[i], t) == 0 {
return i return i
} }
return -i - 1 return -i - 1