git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH] Replace strcmp_icase with strequal_icase

From
Fredrik Gustafsson <iveqy@iveqy.com>
Date
Mar 9, 2013, 08:42 UTC
Message-ID
<1362818574-16873-1-git-send-email-iveqy@iveqy.com>

To improve performance. git status before: user 0m0.020s user 0m0.024s user 0m0.024s user 0m0.020s user 0m0.024s user 0m0.028s user 0m0.024s user 0m0.024s user 0m0.016s user 0m0.028s

git status after: user 0m0.012s user 0m0.008s user 0m0.008s user 0m0.008s user 0m0.008s user 0m0.008s user 0m0.008s user 0m0.004s user 0m0.008s user 0m0.016s

Signed-off-by: Fredrik Gustafsson <iveqy@iveqy.com>
---
 dir.c | 17 ++++++++++++++---
 1 file changed, 14 insertions(+), 3 deletions(-)
diff --git a/dir.c b/dir.c
index 57394e4..2b801e8 100644
--- a/dir.c
+++ b/dir.c
@@ -37,6 +37,17 @@ int fnmatch_icase(const char *pattern, const char *string, int flags)
 	return fnmatch(pattern, string, flags | (ignore_case ? FNM_CASEFOLD : 0));
 }
 
+int strequal_icase(const char *first, const char *second)
+{
+	while (*first && *second) {
+		if( toupper(*first) != toupper(*second))
+			break;
+		first++;
+		second++;
+	}
+	return toupper(*first) == toupper(*second);
+}
+
 inline int git_fnmatch(const char *pattern, const char *string,
 		       int flags, int prefix)
 {
@@ -626,11 +637,11 @@ int match_basename(const char *basename, int basenamelen,
 		   int flags)
 {
 	if (prefix == patternlen) {
-		if (!strcmp_icase(pattern, basename))
+		if (!strequal_icase(pattern, basename))
 			return 1;
 	} else if (flags & EXC_FLAG_ENDSWITH) {
 		if (patternlen - 1 <= basenamelen &&
-		    !strcmp_icase(pattern + 1,
+		    !strequal_icase(pattern + 1,
 				  basename + basenamelen - patternlen + 1))
 			return 1;
 	} else {
@@ -663,7 +674,7 @@ int match_pathname(const char *pathname, int pathlen,
 	 */
 	if (pathlen < baselen + 1 ||
 	    (baselen && pathname[baselen] != '/') ||
-	    strncmp_icase(pathname, base, baselen))
+	    strequal_icase(pathname, base))
 		return 0;
 
 	namelen = baselen ? pathlen - baselen - 1 : pathlen;
-- 
1.8.1.5
Next: Fredrik Gustafsson
Message 1 of 9 in “Replace strcmp_icase with strequal_icase”
  1. Replace strcmp_icase with strequal_icaseFredrik Gustafsson, Mar 9, 2013
  2. Fredrik GustafssonMar 9, 2013
  3. Duy NguyenMar 9, 2013
  4. Duy NguyenMar 9, 2013
  5. Duy NguyenMar 9, 2013
  6. Fredrik GustafssonMar 9, 2013
  7. Duy NguyenMar 9, 2013
  8. Fredrik GustafssonMar 9, 2013
  9. Duy NguyenMar 9, 2013

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.