Browse code

Improve performance of has_match

John Hawthorn authored on 14/09/2014 05:57:26
Showing 1 changed files

  • match.c index f55f954..26151db 100644
... ...
@@ -9,10 +9,14 @@
9 9
 
10 10
 int has_match(const char *needle, const char *haystack){
11 11
 	while(*needle){
12
-		if(!*haystack)
13
-			return 0;
14
-		while(*haystack && tolower(*needle) == tolower(*haystack++))
15
-			needle++;
12
+		char nch = tolower(*needle++);
13
+		for(;;){
14
+			char ch = *haystack++;
15
+			if(!ch)
16
+				return 0;
17
+			else if(nch == tolower(ch))
18
+				break;
19
+		}
16 20
 	}
17 21
 	return 1;
18 22
 }