combine-diff.c: fix performance problem when folding common deleted lines
commit55d5d5bab7c3f9ab6310b9cf436a7935d7d32165
authorJunio C Hamano <gitster@pobox.com>
Wed, 22 Jul 2009 21:48:28 +0000 (22 14:48 -0700)
committerJunio C Hamano <gitster@pobox.com>
Wed, 22 Jul 2009 22:37:55 +0000 (22 15:37 -0700)
treecf01cae48bc434249284890c0fab469504504600
parent78d3b06e0f5e6aaea001ee8e3e7c8e401dc4b244
combine-diff.c: fix performance problem when folding common deleted lines

For a deleted line in a patch with the parent we are looking at, the
append_lost() function finds the same line among a run of lines that were
deleted from the same location by patches from parents we previously
checked.  This is so that patches with two parents

    @@ -1,4 +1,3 @@    @@ -1,4 +1,3 @@
     one                   one
    -two                  -two
     three                 three
    -quatro               -fyra
    +four                 +four

can be coalesced into this sequence, reusing one line that describes the
removal of "two" for both parents.

   @@@ -1,4 -1,4 +1,3 @@@
     one
   --two
     three
   - quatro
    -frya
   ++four

While reading the second patch (that removes "two" and then "fyra"), after
finding where removal of the "two" matches, we need to find existing
removal of "fyra" (if exists) in the removal list, but the match has to
happen after all the existing matches (in this case "two").  The code used
a naïve O(n^2) algorithm to compute this by scanning the whole removal
list over and over again.

This patch remembers where the next scan should be started in the existing
removal list to avoid this.

Noticed by Linus Torvalds.

Signed-off-by: Junio C Hamano <gitster@pobox.com>
combine-diff.c