# [PATCH] builtin/apply.c: fuzzy_matchlines:trying to fix some inefficiencies

2 messages from 2014-03-20 to 2014-03-21. Participants: George Papanikolaou, Jeff King.
Thread: https://gitlist.dev/t/36245

## George Papanikolaou, 2014-03-20 09:35

Subject: [PATCH] builtin/apply.c: fuzzy_matchlines:trying to fix some inefficiencies
Message-ID: <1395308103-16018-1-git-send-email-g3orge.app@gmail.com>
URL: https://gitlist.dev/e/1395308103-16018-1-git-send-email-g3orge.app%40gmail.com

```
Hi again guys,
I forgot to add the signed-of line to the tiny patch I sent earlier for GSOC.
Any ideas about the changes?
Thanks...

Signed-off-by: George Papanikolaou <g3orge.app@gmail.com>
---
 builtin/apply.c | 25 +++++++++----------------
 1 file changed, 9 insertions(+), 16 deletions(-)

diff --git a/builtin/apply.c b/builtin/apply.c
index b0d0986..df2435f 100644
--- a/builtin/apply.c
+++ b/builtin/apply.c
@@ -294,20 +294,16 @@ static int fuzzy_matchlines(const char *s1, size_t n1,
 	const char *last2 = s2 + n2 - 1;
 	int result = 0;
 
+	/* early return if both lines are empty */
+	if ((s1 > last1) && (s2 > last2))
+		return 1;
+
 	/* ignore line endings */
 	while ((*last1 == '\r') || (*last1 == '\n'))
 		last1--;
 	while ((*last2 == '\r') || (*last2 == '\n'))
 		last2--;
 
-	/* skip leading whitespace */
-	while (isspace(*s1) && (s1 <= last1))
-		s1++;
-	while (isspace(*s2) && (s2 <= last2))
-		s2++;
-	/* early return if both lines are empty */
-	if ((s1 > last1) && (s2 > last2))
-		return 1;
 	while (!result) {
 		result = *s1++ - *s2++;
 		/*
@@ -315,18 +311,15 @@ static int fuzzy_matchlines(const char *s1, size_t n1,
 		 * both buffers because we don't want "a b" to match
 		 * "ab"
 		 */
-		if (isspace(*s1) && isspace(*s2)) {
-			while (isspace(*s1) && s1 <= last1)
-				s1++;
-			while (isspace(*s2) && s2 <= last2)
-				s2++;
-		}
+		while (isspace(*s1) && s1 <= last1)
+			s1++;
+		while (isspace(*s2) && s2 <= last2)
+			s2++;
 		/*
 		 * If we reached the end on one side only,
 		 * lines don't match
 		 */
-		if (
-		    ((s2 > last2) && (s1 <= last1)) ||
+		if (((s2 > last2) && (s1 <= last1)) ||
 		    ((s1 > last1) && (s2 <= last2)))
 			return 0;
 		if ((s1 > last1) && (s2 > last2))
-- 
1.9.0

```

## Jeff King, 2014-03-21 06:32

Subject: Re: [PATCH] builtin/apply.c: fuzzy_matchlines:trying to fix some inefficiencies
Message-ID: <20140321063215.GA744@sigill.intra.peff.net>
URL: https://gitlist.dev/e/20140321063215.GA744%40sigill.intra.peff.net
In-Reply-To: <1395308103-16018-1-git-send-email-g3orge.app@gmail.com>

```
On Thu, Mar 20, 2014 at 11:35:03AM +0200, George Papanikolaou wrote:

> Hi again guys,
> I forgot to add the signed-of line to the tiny patch I sent earlier for GSOC.
> Any ideas about the changes?
> Thanks...

You don't give any detail on the inefficiencies, or what specific
benchmark is made faster. Have you done any timings to show that there
is a measurable improvement? If so, can you share them in the commit
message?

-Peff

```
