Repository navigation
sed: close addr,~N range when skipped target line has passed - #710
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #710 +/- ##
=======================================
Coverage 95.43% 95.44%
=======================================
Files 14 14
Lines 7740 7742 +2
Branches 467 467
=======================================
+ Hits 7387 7389 +2
Misses 352 352
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 3.52%2 warnings
Performance Changes
Tip Curious why performance improved? Comment Comparing |
| Address::StepEnd(step) => { | ||
| // Inclusive end on multiple of step | ||
| if linenum.is_multiple_of(*step) { | ||
| let target = if *step == 0 { |
There was a problem hiding this comment.
StepEnd(0) never sets start_line (see the StepEnd(0) case at line 161), so this branch is dead code.
let target = (start / step + 1) * step; would do, no?
There was a problem hiding this comment.
Good catch! Updated in 7cd4e9d to let target = (start / step + 1) * step;, eliminating the dead branch.
|
Thanks for your PR |
Fixes #655
Summary
An
addr,~Nrange should end at the first line at or afteraddrwhose line number is a multiple ofN(or the subsequent multiple ifaddris already a multiple ofN).Previously,
Address::StepEnd(step)inapplies()only checked whether the current line was an exact multiple ofstep(linenum.is_multiple_of(*step)), ignoring the computed end line target relative tostart. If the exact target line was skipped (e.g., via an earlierdcommand, branch, or nested block), the range stayed open until the next multiple ofstep, or the end of input.Solution
linenum >= target, close the range (command.start_line = None;) and setcontext.last_address = true;.tests/by-util/test_sed.rscovering skipped end lines (3d;2,~3p,3,4d;2,~3p) and starting on multiples (3,~3p).