Skip to content
Myr

Revert "fix: reduce/foreach state variable should not be reset each iteration" (#3349)

Before adoption: this commit came in with the history the project adopted, so no landing records it.

This reverts 96e8d893c10ed2f7656ccb8cfa39a9a291663a7e. The change introduced a serious performance regression as reported in #3345.

authored by itchyny · committed by GitHub · parent a587ddc · Browse files · 2 files+2 added−10 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

2 files+2 added−10 removed

  • tests:+0 added−8 removed
  • other:+2 added−2 removed

2 files+2 added−10 removed

modified:src/compile.c+2 added-2 removed
829 unmodified lines
830 block res_var = gen_op_var_fresh(STOREV, "reduce");831 block loop = BLOCK(gen_op_simple(DUPN),832 source,833 bind_alternation_matchers(matcher,834 BLOCK(gen_op_bound(LOADV, res_var),834 BLOCK(gen_op_bound(LOADVN, res_var),835 body,836 gen_op_bound(STOREV, res_var))),837 gen_op_simple(BACKTRACK));838 return BLOCK(gen_op_simple(DUP),
15 unmodified lines
854 // destructure the value into variable(s) for all the code855 // in the body to see856 bind_alternation_matchers(matcher,857 // load the loop state variable858 BLOCK(gen_op_bound(LOADV, state_var),858 BLOCK(gen_op_bound(LOADVN, state_var),859 // generate updated state860 update,861 // save the updated state for value extraction862 gen_op_simple(DUP),
517 unmodified lines
modified:tests/jq.test-8 removed
356 unmodified lines
357[foreach .[] as $x (0; . + $x) as $x | $x]358[1,2,3]359[1,3,6]360361[foreach range(5) as $x (0; .+$x | select($x!=2); [$x,.])]362null363[[0,0],[1,1],[3,4],[4,8]]364361[limit(3; .[])]362[11,22,33,44,55,66,77,88,99]363[11,22,33]364
550 unmodified lines
915reduce . as $n (.; .)916null917null918923reduce range(5) as $x (0; .+$x | select($x!=2))924null9258926919# Destructuring920. as {$a, b: [$c, {$d}]} | [$a, $c, $d]921{"a":1, "b":[2,{"d":3}]}922[1,2,3]
1579 unmodified lines