Repository navigation
sed: write appended text, R text and e output as GNU sed does - #589
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #589 +/- ##
==========================================
- Coverage 94.82% 94.81% -0.02%
==========================================
Files 14 14
Lines 7212 7217 +5
Branches 428 428
==========================================
+ Hits 6839 6843 +4
- Misses 372 373 +1
Partials 1 1
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Merging this PR will improve performance by 35.79%
|
| Benchmark | BASE |
HEAD |
Efficiency | |
|---|---|---|---|---|
| ⚡ | access_log_append |
1.5 s | 1.1 s | +35.79% |
Tip
Curious why performance improved? Comment @codspeedbot explain why performance improved on this PR, or directly use the CodSpeed MCP with your agent.
Comparing DePasqualeOrg:fix-r-separator-and-q-appends (b9941aa) with main (479c4be)
3ab6bde to
ae5f8dc
Compare
Q|
GNU sed testsuite comparison: |
ae5f8dc to
ed72266
Compare
|
|
||
| /// Output any data queued for output at the end of the cycle. | ||
| fn flush_appends(output: &mut OutputBuffer, context: &mut ProcessingContext) -> UResult<()> { | ||
| if !context.append_elements.is_empty() { |
There was a problem hiding this comment.
could copy_file flush the pending newline itself, before the open?
then this block isn't needed, write_raw already does it for text
| context.stop_processing = true; | ||
| context.quiet = true; | ||
| // Like GNU sed, discard text queued by `a`, `r` and `R`. | ||
| context.append_elements.clear(); |
There was a problem hiding this comment.
the Q and l fixes are unrelated to the r/R/e output change
please split them into separate PRs, thanks
ed72266 to
698bcb7
Compare
| pub fn copy_file(&mut self, path: &PathBuf) -> io::Result<()> { | ||
| // As in GNU sed, write the deferred newline even when the file is | ||
| // empty or cannot be read. | ||
| self.flush_pending_newline()?; |
There was a problem hiding this comment.
could copy_file just call self.write_raw(b"")? here?
same flush_pending_newline + flush_mmap as write_raw
698bcb7 to
76bbc1d
Compare
76bbc1d to
b9941aa
Compare
|
Thanks for your PR |
When the last line of input has no final newline and the cycle ends with text queued by
a,rorR, GNU sed first writes the missing newline and then the queued text, even when anrfile is missing or empty. uutils sed joins them instead:printf a | sed 'r f'printsaimmediately followed by the contents off. This PR writes the missing newline before any text queued for the end of the cycle.GNU sed copies the line that
Rreads, and the output of thee commandform, exactly as they are. uutils sed treats them as lines and adds a newline when they lack one. With a filefthat containsxand no newline,printf 'a\nb\n' | sed 'R f'printsxandbon separate lines, while GNU sed printsxb. Likewise,printf 'a\n' | sed '1e printf hi'printshion a line of its own, while GNU sed printshia. This PR addsOutputBuffer::write_raw, which writes a newline that the previous output line lacks and then the bytes unchanged, and uses it for this text.