Page MenuHomeFreeBSD

diff3: Clean up printing of ranges for edscript output
ClosedPublic

Authored by thj on Apr 18 2022, 1:22 PM.
Tags
None
Referenced Files
Unknown Object (File)
Feb 13 2024, 2:42 AM
Unknown Object (File)
Feb 2 2024, 5:51 AM
Unknown Object (File)
Jan 3 2024, 6:19 PM
Unknown Object (File)
Dec 23 2023, 4:37 AM
Unknown Object (File)
Dec 6 2023, 5:04 AM
Unknown Object (File)
Nov 14 2023, 7:26 PM
Unknown Object (File)
Nov 12 2023, 6:24 PM
Unknown Object (File)
Oct 13 2023, 6:33 PM
Subscribers

Details

Summary

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

Repository
rG FreeBSD src repository
Lint
Lint Not Applicable
Unit
Tests Not Applicable

Event Timeline

thj requested review of this revision.Apr 18 2022, 1:22 PM
usr.bin/diff3/diff3.c
536

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.
usr.bin/diff3/diff3.c
536

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.