Skip to content

Commit edbc1da

Browse files
authored
Revert "fix: reduce/foreach state variable should not be reset each iteration" (#3349)
This reverts 96e8d89. The change introduced a serious performance regression as reported in #3345.
1 parent a587ddc commit edbc1da

File tree

2 files changed

+2
-10
lines changed

2 files changed

+2
-10
lines changed

src/compile.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -831,7 +831,7 @@ block gen_reduce(block source, block matcher, block init, block body) {
831831
block loop = BLOCK(gen_op_simple(DUPN),
832832
source,
833833
bind_alternation_matchers(matcher,
834-
BLOCK(gen_op_bound(LOADV, res_var),
834+
BLOCK(gen_op_bound(LOADVN, res_var),
835835
body,
836836
gen_op_bound(STOREV, res_var))),
837837
gen_op_simple(BACKTRACK));
@@ -855,7 +855,7 @@ block gen_foreach(block source, block matcher, block init, block update, block e
855855
// in the body to see
856856
bind_alternation_matchers(matcher,
857857
// load the loop state variable
858-
BLOCK(gen_op_bound(LOADV, state_var),
858+
BLOCK(gen_op_bound(LOADVN, state_var),
859859
// generate updated state
860860
update,
861861
// save the updated state for value extraction

tests/jq.test

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -358,10 +358,6 @@ null
358358
[1,2,3]
359359
[1,3,6]
360360

361-
[foreach range(5) as $x (0; .+$x | select($x!=2); [$x,.])]
362-
null
363-
[[0,0],[1,1],[3,4],[4,8]]
364-
365361
[limit(3; .[])]
366362
[11,22,33,44,55,66,77,88,99]
367363
[11,22,33]
@@ -920,10 +916,6 @@ reduce . as $n (.; .)
920916
null
921917
null
922918

923-
reduce range(5) as $x (0; .+$x | select($x!=2))
924-
null
925-
8
926-
927919
# Destructuring
928920
. as {$a, b: [$c, {$d}]} | [$a, $c, $d]
929921
{"a":1, "b":[2,{"d":3}]}

0 commit comments

Comments
 (0)