mirror of
https://github.com/stedolan/jq.git
synced 2024-05-11 05:55:39 +00:00
Revert "reduce: handle empty updates (fix #1313)"
This reverts commit e24af3c78e78a3aab05a2800d825d56f1d842b1b. While the semantics are desirable, there is no way to implement them efficiently. The reason is that in order to handle backtracking (empty) from the state update expression, we have to retain a reference to the reduction state value in order to restore it upon backtracking. Retaining a reference to the reduction state kills performance by causing lots of additional memory allocations and garbage because the input to the update expression will always have at least two references, thus no changes to it can be done in-place, and all changes end up being CoW changes. Avoiding this is the very reason for the LOADVN instruction (leaving `null` in the variable loaded from).
This commit is contained in:
@ -1,7 +1,7 @@
|
||||
.\" generated with Ronn/v0.7.3
|
||||
.\" http://github.com/rtomayko/ronn/tree/0.7.3
|
||||
.
|
||||
.TH "JQ" "1" "May 2017" "" ""
|
||||
.TH "JQ" "1" "December 2017" "" ""
|
||||
.
|
||||
.SH "NAME"
|
||||
\fBjq\fR \- Command\-line JSON processor
|
||||
@ -2100,7 +2100,7 @@ The \fBstrftime(fmt)\fR builtin formats a time (GMT) with the given format\. The
|
||||
The format strings for \fBstrptime\fR and \fBstrftime\fR are described in typical C library documentation\. The format string for ISO 8601 datetime is \fB"%Y\-%m\-%dT%H:%M:%SZ"\fR\.
|
||||
.
|
||||
.P
|
||||
jq may not support some or all of this date functionality on some systems\.
|
||||
jq may not support some or all of this date functionality on some systems\. In particular, the \fB%u\fR and \fB%j\fR specifiers for \fBstrptime(fmt)\fR are not supported on macOS\.
|
||||
.
|
||||
.IP "" 4
|
||||
.
|
||||
@ -2378,7 +2378,7 @@ break $out
|
||||
.P
|
||||
because no label \fB$out\fR is visible\.
|
||||
.
|
||||
.SS "Error Suppresion / Optional Operator: ?"
|
||||
.SS "Error Suppression / Optional Operator: ?"
|
||||
The \fB?\fR operator, used as \fBEXP?\fR, is shorthand for \fBtry EXP\fR\.
|
||||
.
|
||||
.IP "" 4
|
||||
@ -2861,25 +2861,10 @@ For each result that \fB\.[]\fR produces, \fB\. + $item\fR is run to accumulate
|
||||
0 | (3 as $item | \. + $item) |
|
||||
(2 as $item | \. + $item) |
|
||||
(1 as $item | \. + $item)
|
||||
.
|
||||
.fi
|
||||
.
|
||||
.IP "" 0
|
||||
.
|
||||
.P
|
||||
If the reduction update expression outputs \fBempty\fR (that is, no values), then the reduction state is left as\-is\. For example, \fBreduce range(4) as $n ({}; if \.==2 then empty else \.[$n|tostring] |= $n)\fR will produce \fB{"0":0,"1":1,"3":3}\fR\.
|
||||
.
|
||||
.IP "" 4
|
||||
.
|
||||
.nf
|
||||
|
||||
jq \'reduce \.[] as $item (0; \. + $item)\'
|
||||
[10,2,5,3]
|
||||
=> 20
|
||||
|
||||
jq \'reduce \.[] as $n ([]; if $n%2==0 then empty else \. + [$n] end)\'
|
||||
[0,1,2,3,4,5]
|
||||
=> [1,3,5]
|
||||
.
|
||||
.fi
|
||||
.
|
||||
|
Reference in New Issue
Block a user