Skip to content

Commit

Permalink
builtin-apply.c: optimize match_beginning/end processing a bit.
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Junio C Hamano committed Feb 5, 2008
1 parent b94f2ed commit ecf4c2e
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions builtin-apply.c
Original file line number Diff line number Diff line change
Expand Up @@ -1579,6 +1579,16 @@ static int find_pos(struct image *img,
if (preimage->nr > img->nr)
return -1;

/*
* If match_begining or match_end is specified, there is no
* point starting from a wrong line that will never match and
* wander around and wait for a match at the specified end.
*/
if (match_beginning)
line = 0;
else if (match_end)
line = img->nr - preimage->nr;

try = 0;
for (i = 0; i < line; i++)
try += img->line[i].len;
Expand Down

0 comments on commit ecf4c2e

Please sign in to comment.