From 964caad8760807b9487a594546e53e8f2bcba0e9 Mon Sep 17 00:00:00 2001 From: Muh Muhten Date: Fri, 22 Mar 2019 00:18:15 -0400 Subject: [PATCH] Faster limit/2 by saving an empty call in the loop --- src/builtin.jq | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/builtin.jq b/src/builtin.jq index a6cdabe58a..49caae2463 100644 --- a/src/builtin.jq +++ b/src/builtin.jq @@ -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