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"
"regexp"
"slices"
"sort"
"strconv"
"strings"
"sync"
@@ -438,9 +437,7 @@ func add(xs iter.Seq[any]) any {
case []any:
switch w := v.(type) {
case nil:
s := make([]any, len(x))
copy(s, x)
v = s
v = slices.Clone(x)
continue
case []any:
v = append(w, x...)
@@ -769,6 +766,13 @@ 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 {
@@ -1484,10 +1488,8 @@ func (a allocator) allocated(v any) bool {
return ok
}
// release forgets every allocated address when the value is one of them. It is
// called wherever a value the allocator created is handed to a query, which
// 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.
// 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:
@@ -1523,10 +1525,9 @@ func funcSetpathWithAllocator(v any, args []any) any {
return setpath(v, args[0], args[1], args[2].(allocator))
}
// Used in compiler#compileModify. The value at the path is passed to the
// update function, which may store it in any number of places, so it must not
// be modified in place afterwards. It is registered under the name of getpath
// to keep tracking paths through the call.
// 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)
@@ -1610,8 +1611,7 @@ func update(v any, path []any, n any, a allocator) (any, error) {
return nil, &expectedArrayError{v}
}
case map[string]any:
// A path element is an object only when slicing an array, and it stays
// reachable through the path, so it must not be modified in place.
// A slice bound stays reachable through the path.
a.release(p)
switch v := v.(type) {
case nil:
@@ -1805,14 +1805,9 @@ func funcGetpath(v, p any) any {
}
u := v
for _, x := range path {
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}
v = funcIndex2(nil, v, x)
if err, ok := v.(error); ok {
return &func1WrapError{"getpath", u, p, err}
}
}
return v
@@ -1856,10 +1851,8 @@ func funcBsearch(v, t any) any {
if !ok {
return &func1TypeError{"bsearch", v, t}
}
i := sort.Search(len(vs), func(i int) bool {
return Compare(vs[i], t) >= 0
})
if i < len(vs) && Compare(vs[i], t) == 0 {
i, ok := slices.BinarySearchFunc(vs, t, Compare)
if ok {
return i
}
return -i - 1