Repository navigation
date: print jiff-only conversions %f, %.f, %Q, %:Q literally - #16520
emirmrkaljevic wants to merge 3 commits into
Conversation
Merging this PR will regress 2 benchmarks2 warnings, 1 note
Warning Please fix the performance issues or acknowledge them on CodSpeed. Performance Changes
Tip Investigate this regression by commenting Comparing Footnotes
|
| /// them and prints an unknown conversion literally, so `+%Q` must stay `%Q`. | ||
| /// Turn the leading `%` of such a conversion into `%%` before jiff sees it. | ||
| fn escape_non_gnu_specifiers(fmt: &str) -> String { | ||
| if !fmt.contains('%') { |
There was a problem hiding this comment.
nearly every format has a %, so this always allocates and rescans; could you please guard on f/Q/. like substitute_epoch_seconds does with s? should fix the codspeed regression
There was a problem hiding this comment.
Done in 7befa0a: it returns early unless the format has a % and one of O, f, Q or ., and it returns a Cow, so nothing is allocated when nothing changes.
| out.push('%'); | ||
| start = i; | ||
| } | ||
| i = j.max(i + 1); |
There was a problem hiding this comment.
j is always > i here, i = j; is enough, no?
There was a problem hiding this comment.
Yes, changed to i = j;.
| // to the floored epoch second before jiff sees the format string. | ||
| let fmt_owned = strip_o_modifier(&substitute_epoch_seconds(fmt, date)); | ||
| let fmt_owned = | ||
| escape_non_gnu_specifiers(&strip_o_modifier(&substitute_epoch_seconds(fmt, date))); |
There was a problem hiding this comment.
three passes over the format now (epoch, O, this), could this one be merged with strip_o_modifier?
There was a problem hiding this comment.
Merged: strip_o_modifier and the escaping are now one function, adapt_format_for_jiff, so it is two passes again (epoch + this one). While at it, %Of and %OQ now stay literal like GNU (before they turned into %f/%Q), added to the test.
|
thanks for picking this up! |
|
Thanks for the review. Pushed 7befa0a with the guard and the merged pass; waiting for CodSpeed to rerun. |
|
thanks for the work on this! |
|
/rerun OpenBSD |
| } | ||
| i = j; | ||
| } | ||
| if start == 0 { |
There was a problem hiding this comment.
start is still 0 after escaping a conversion at index 0, so date +%Q or date +%f alone still prints UTC/5. Could you please track the change with a flag?
There was a problem hiding this comment.
Good catch, thanks. Fixed in d1d51b1: it now tracks the change with a changed flag instead of start == 0.
| .arg("-d") | ||
| .arg("@1.5") | ||
| .arg("+%Q %:Q %f %.3f %-f %%Q %Of %OQ %s") | ||
| .succeeds() |
There was a problem hiding this comment.
please also test +%Q and +%.3f alone: here the later escapes hide the index 0 case
There was a problem hiding this comment.
Added test_date_non_gnu_specifier_at_start_is_literal with +%Q, +%f and +%.3f on their own.
| } | ||
| if bytes.get(i + 1) == Some(&b'O') && bytes.get(i + 2).is_some_and(u8::is_ascii_alphabetic) | ||
| { | ||
| if matches!(bytes[i + 2], b'f' | b'Q') { |
There was a problem hiding this comment.
this is the same push / % / start = i as the one below, could they share the code?
There was a problem hiding this comment.
Yes, both now call a small escape_percent helper.
|
GNU testsuite comparison: |
| } | ||
|
|
||
| #[test] | ||
| fn test_date_non_gnu_specifier_at_start_is_literal() { |
|
Binary size comparison: |
|
Duplicate of #14672. |
|
I do not think this should be merged; I think we should document the Originally posted by @xtqqczze in #14672 (review) |
|
As per POSIX, the current behavior is not non-compliant. POSIX says the following about
So Originally posted by @xtqqczze in #14672 (comment) |
|
Thanks, fair point, and I missed that #14672 already covers this. Since the direction there is to keep %f/%Q as extensions and document them, I will close this one. Thanks @sylvestre and @xtqqczze for the reviews. |
Fixes #16519.
jiff knows
%f,%.f(with an optional precision),%Qand%:Q; GNUdatedoes not and prints them unchanged. Before handing the format to jiff, escape the%of those conversions (including any flags, width or colons), next to the existing%Ohandling.GNU also pads an unknown conversion to its width (
%5Qgives%5Q); that is not covered here.Added
test_date_non_gnu_specifiers_are_literal.Found with behave.