[PATCH 05/13] builtin-apply.c: optimize match_beginning/end processing a bit.

!MAILaRCHIVE_VOTE_RePLACE
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]
To: <git@...>
Date: Saturday, February 2, 2008 - 6:54 am

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>
---
 builtin-apply.c |   10 ++++++++++
 1 files changed, 10 insertions(+), 0 deletions(-)

diff --git a/builtin-apply.c b/builtin-apply.c
index e046e87..dc650f1 100644
--- a/builtin-apply.c
+++ b/builtin-apply.c
@@ -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;
-- 
1.5.4.2.g41ac4

-
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]

Messages in current thread:
[PATCH 05/13] builtin-apply.c: optimize match_beginning/end ..., Junio C Hamano, (Sat Feb 2, 6:54 am)