Page MenuHomeFreeBSD

diff3: Clean up printing of ranges for edscript output

Authored by thj on Apr 18 2022, 1:22 PM.



Replace the edscript code that tracked and printed lines using byte
offsets with code that can work from line offsets.

This tidies up the reduces duplication in the edscript output code. It
also fixes the usage of the de struct so that it only tracks diffs as
line offsets rather than the usage changing from line offsets to byte
offsets during the lifetime of diff3.

Large files with large numbers of ranges will probably suffer in
performance here, but as we don't use diff3 yet this isn't a regression.
Include a warning for future hackers so they have a place to start
hacking from.

Diff Detail

rG FreeBSD src repository
Automatic diff as part of commit; lint not applicable.
Automatic diff as part of commit; unit tests not applicable.

Event Timeline

thj requested review of this revision.Apr 18 2022, 1:22 PM

Missing space after while and in if (++i > r->to-1).
I wonder if it would make more sense to never free and nullify the buffer within the loop, but once it's over. I'd expect it'd be cheaper not to allocate every iteration, the buffer will be expanded and the pointer updated.

  • Don't free line buffer in getline loop
thj marked an inline comment as done.Apr 18 2022, 3:09 PM
thj added inline comments.

Great points, rereading the getline man page and its clearer how it should be used.

Maybe if the file was mmapped and the r->fromth line found via memchr() or similar, that would be faster.

This revision is now accepted and ready to land.Apr 19 2022, 8:32 AM
This revision was automatically updated to reflect the committed changes.
thj marked an inline comment as done.