Repository navigation
sed: print the c text when a numeric, relative or step range ends - #617
jayhemnani9910 wants to merge 2 commits into
Conversation
There was a problem hiding this comment.
Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota.
An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing. Review the Copilot code review billing settings.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #617 +/- ##
==========================================
+ Coverage 94.93% 95.37% +0.43%
==========================================
Files 14 14
Lines 7292 7675 +383
Branches 434 459 +25
==========================================
+ Hits 6923 7320 +397
+ Misses 368 354 -14
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:
|
| Ok(false) | ||
| } else { | ||
| if linenum - start == *n { | ||
| command.start_line = None; |
There was a problem hiding this comment.
this also changes the restart for +N, e.g. printf 'a\na\na\na\n' | sed '/a/,+1d'
please add a test for it too
| // when the range is negated, then start the next cycle. | ||
| pattern.clear(); | ||
| if command.addr2.is_none() || context.last_address || reader.last_line()? { | ||
| if command.addr2.is_none() || command.non_select || context.last_address { |
There was a problem hiding this comment.
dropping reader.last_line() changes the output for a range still open at EOF, please run the GNU testsuite to make sure nothing regresses:
git clone https://github.com/mirror/sed.git ../gnu.sed
./util/run-gnu-testsuite.sh
| @@ -111,6 +121,7 @@ fn applies( | |||
| // Inclusive end on multiple of step | |||
| if linenum.is_multiple_of(*step) { | |||
There was a problem hiding this comment.
what about 4,~4c\X? i think GNU matches only line 4 when addr1 is already a multiple of N, here the range would go on until 8
could you please check and add it to the test?
|
processor.rs:100 ( processor.rs:729 (GNU testsuite): ran processor.rs:122 ( The new cases fail on the PR base and pass here. |
There was a problem hiding this comment.
Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.
An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing. Review the Copilot code review billing settings.
Merging this PR will improve performance by 2.81%2 warnings
Performance Changes
Tip Curious why performance improved? Comment Comparing |
With a range whose end is a line number,
+Nor~N,cdeletes the lines but never prints its text. GNU sed 4.9 vs main:The same for
2,+2cand2,~4c;/re/,/re/cworks. Related cases in the same code:appliesonly setlast_addresswhen a regex or$ended the range, and never cleared it, soceither missed the end or printed on every later line;calso printed at the last input line of an unfinished range and skipped negated ranges. Nowlast_addressis cleared for each command and set when a line,+Nor~Nend is reached; the range closes on that line, so the next line can start it again (the/a/,3dcase).cprints at the end of a range, and on every line of a negated one.New tests
test_change_command_prints_text_at_range_endandtest_range_with_line_end_restarts_on_next_linefail on main.cargo test: 748 passed (746 on main plus the two), clippy and fmt clean. 26 scripts withc,d,p,n,Nand blocks over numeric, relative, step and regex ranges give the same output as GNU sed 4.9 on three inputs.