]> git.ipfire.org Git - thirdparty/git.git/commit
diff --anchored: avoid checking unmatched lines
authorPhillip Wood <phillip.wood@dunelm.org.uk>
Thu, 12 Feb 2026 15:53:50 +0000 (15:53 +0000)
committerJunio C Hamano <gitster@pobox.com>
Thu, 12 Feb 2026 17:28:49 +0000 (09:28 -0800)
commitdd2a4c0c7acb588abbf3c3a39ca755ce8aeee3b0
tree9734c73658b1f543612b90c09aac1733c2f84a9f
parent67ad42147a7acc2af6074753ebd03d904476118f
diff --anchored: avoid checking unmatched lines

For a line to be an anchor it has to appear in each of the files being
diffed exactly once. With that in mind lets delay checking whether
a line is an anchor until we know there is exactly one instance of
the line in each file. As each line is checked at most once, there
is no need to cache the result of is_anchor() and we can drop that
field from the hashmap entries. When diffing 5000 recent commits in
git.git this gives a modest speedup of ~2%. In the (rather extreme)
example below that consists largely of deletions the speedup is ~16%.

    seq 0 10000000 >old
    printf '%s\n' 300000 100000 200000 >new
    git diff --no-index --anchored=300000 old new

Signed-off-by: Phillip Wood <phillip.wood@dunelm.org.uk>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
xdiff/xpatience.c