Repository navigation
sed: accept first~step as the start of an address range - #619
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 #619 +/- ##
==========================================
+ Coverage 94.15% 94.17% +0.02%
==========================================
Files 14 14
Lines 5745 5768 +23
Branches 463 470 +7
==========================================
+ Hits 5409 5432 +23
Misses 335 335
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:
|
| && let Some(Address::Line(first)) = cmd.addr1 | ||
| && (first, step_n) != (0, 0) | ||
| { | ||
| cmd.addr1 = Some(Address::Step(first, step_n)); |
There was a problem hiding this comment.
for a step of 0, could we keep Address::Line(first)?
GNU treats 1~0 as a plain line number, so e.g. 1d;1~0,3p should start the range on line 2 like 1d;1,3p does.
it would also remove the step == 0 case in match_address.
|
|
||
| line.eat_spaces(); | ||
| if n_addr == 1 && !line.eol() && matches!(line.current(), ',' | '~') { | ||
| while n_addr == 1 && !line.eol() && matches!(line.current(), ',' | '~') { |
There was a problem hiding this comment.
turning the if into a while just to loop once more is a bit hard to follow
could the second address be read explicitly after the step instead?
| RelLine(usize), // Relative line | ||
| Last, // Last line | ||
| StepMatch(usize), // Lines matching specified step from first | ||
| Step(usize, usize), // first~step starting a range: first, first+step, ... |
There was a problem hiding this comment.
Step next to StepMatch and StepEnd is confusing, maybe StepStart?
| ("1~3,+1p", "1\n2\n4\n5\n7\n8\n10\n11\n"), | ||
| ("1~3,5p", "1\n2\n3\n4\n5\n7\n10\n"), | ||
| ("0~4,~3p", "4\n5\n6\n8\n9\n12\n"), | ||
| ("2~3,/7/p", "2\n3\n4\n5\n6\n7\n8\n9\n10\n11\n12\n"), |
There was a problem hiding this comment.
please add 0~3,/x/ too, it shouldn't behave like 0,/x/
and a case with a skipped start like 1d;1~0,3p
|
All four done in 3b6e2c7:
|
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 6.56%2 warnings
Performance Changes
Tip Curious why performance improved? Comment Comparing |
GNU sed starts a range on every line first~step selects, so '1~3,+1p' prints lines 1, 2, 4, 5, ... Until now the ',' after the step was rejected as an unknown command.
Move the parsing of `,addr2` / `~N` into compile_second_address and call it a second time after `first~step,` instead of looping. Keep `first~0` as a plain line number so `1d;1~0,3p` starts the range on line 2 like `1d;1,3p`, and rename Address::Step to StepStart.
3b6e2c7 to
d865e40
Compare
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.
|
Thanks for your PR |
GNU sed lets
first~stepstart a range: the range starts on every line the step selects and ends at the second address as usual. uutils sed rejects the,:GNU sed 4.9 prints
1 2 4 5 7 8 10 11. Same for1~3,5p,0~4,~3p,2~3,/7/p.The step address was stored as
addr1 = first,addr2 = StepMatch(step), so a second address had nowhere to go. When a,followsfirst~step, the compiler now turns addr1 into a newAddress::Step(first, step)and reads the second address as for any range;match_addressmatches it onfirst, first+step, ...(onlyfirstfor a step of 0).0~0,Nis still rejected, as GNU does.Tests:
test_step_match_starts_rangewith six scripts whose expected output is GNU sed 4.9's (fails on main), andtest_step_match_zero_zero_range_start.cargo test: 356 passed (354 on main), clippy and fmt clean.