@matheusbsbs / matheus-bagliano / commits / ecf4c2ec6b
Fork 0

builtin-apply.c: optimize match_beginning/end processing a bit.

Wnen the caller knows the hunk needs to match at the beginning or at the end, there is no point starting from the line number that is found in the patch and trying match with increasing offset. The logic to find matching lines was made more line oriented with the previous patch and this optimization is now trivial. Signed-off-by: Junio C Hamano <gitster@pobox.com>

Junio C Hamano committed Jan 28, 2008 at 03:04 UTC ecf4c2ec6ba6dc39e72c6b37f2a238e28fec2dc1
1 file changed +10
builtin-apply.c
+10
@@ -1579,6 +1579,16 @@ static int find_pos(struct image *img,
1579 if (preimage->nr > img->nr)
1580 return -1;
1581
1582 + /*
1583 + * If match_begining or match_end is specified, there is no
1584 + * point starting from a wrong line that will never match and
1585 + * wander around and wait for a match at the specified end.
1586 + */
1587 + if (match_beginning)
1588 + line = 0;
1589 + else if (match_end)
1590 + line = img->nr - preimage->nr;
1591 +
1592 try = 0;
1593 for (i = 0; i < line; i++)
1594 try += img->line[i].len;