Skip to content

Commit

Permalink
Faster limit/2 by saving an empty call in the loop
Browse files Browse the repository at this point in the history
  • Loading branch information
muhmuhten committed Mar 22, 2019
1 parent 0daa5a7 commit 964caad
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion src/builtin.jq
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ def until(cond; next):
if cond then . else (next|_until) end;
_until;
def limit($n; exp):
if $n > 0 then label $out | foreach exp as $item ($n; .-1; $item, if . <= 0 then break $out else empty end)
if $n > 0 then label $out | foreach exp as $item ($n; .-1; if . > 0 then $item else $item, break $out end)
elif $n == 0 then empty
else exp end;
# range/3, with a `by` expression argument
Expand Down

0 comments on commit 964caad

Please sign in to comment.