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

Re: [PATCH] Replace strcmp_icase with strequal_icase

From
Fredrik Gustafsson <iveqy@iveqy.com>
Date
Mar 9, 2013, 11:08 UTC
Message-ID
<20130309110815.GA8328@paksenarrion.iveqy.com>
In-Reply-To
<CACsJy8BbXjJeTgo0DzKKMY7B3NZB=r3r+Z-WsWJR=t00DkTVzQ@mail.gmail.com>
On Sat, Mar 09, 2013 at 05:54:45PM +0700, Duy Nguyen wrote:
Show 17 quoted lines
> On Sat, Mar 9, 2013 at 5:40 PM, Duy Nguyen <pclouds@gmail.com> wrote:
> > On Sat, Mar 9, 2013 at 3:42 PM, Fredrik Gustafsson <iveqy@iveqy.com> wrote:
> >> To improve performance.
> >
> > BTW, by rolling our own string comparison, we may lose certain
> > optimizations done by C library. In case of glibc, it may choose to
> > run an sse4.2 version where 16 bytes are compared at a time. Maybe we
> > encounter "string not equal" much often than "string equal" and such
> > an optimization is unncessary, I don't know. Measured numbers say it's
> > unncessary as my cpu supports sse4.2.
> 
> Another problem is locale. Git's toupper() does not care about locale,
> which should be fine in most cases. strcasecmp is locale-aware, our
> new str[n]equal_icase is not. It probably does not matter for
> (ascii-based) pathnames, I guess. core.ignorecase users, any comments?
> -- 
> Duy

Actually when implemented a str[n]equal_icase that actually should work. I break the test suite when trying to replace strncmp_icase(pathname, base, baselen)) on line 711 in dir.c and I don't get any significant improvements.

I like work in this area though, slow commit's are my worst git problem. I often have to wait 10s. for a commit to be calculated.

-- 
Med vänliga hälsningar
Fredrik Gustafsson

tel: 0733-608274
e-post: iveqy@iveqy.com


From c5d1f436cdbe7b12c67e81cf1d2904d1fb2e9b6b Mon Sep 17 00:00:00 2001
From: Fredrik Gustafsson <iveqy@iveqy.com>
Date: Sat, 9 Mar 2013 09:27:16 +0100
Subject: [PATCH] Replace strcmp_icase with strequal_icase

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:
wip

Tried to replace strncmp_icase on line 711 in dir.c but then failed to
run the testsuite. Did not got any relevant speed improvements of this.
---
 dir.c |   49 +++++++++++++++++++++++++++++++++++++++++++++++--
 1 files changed, 47 insertions(+), 2 deletions(-)

diff --git a/dir.c b/dir.c
index 57394e4..aace36a 100644
--- a/dir.c
+++ b/dir.c
@@ -37,6 +37,51 @@ int fnmatch_icase(const char *pattern, const char *string, int flags)
 	return fnmatch(pattern, string, flags | (ignore_case ? FNM_CASEFOLD : 0));
 }
 
+int strnequal_icase(const char *first, const char *second, size_t count)
+{
+	if (ignore_case) {
+		while (*first && *second && count) {
+			if( toupper(*first) != toupper(*second))
+				break;
+			first++;
+			second++;
+			count--;
+		}
+		return toupper(*first) == toupper(*second);
+	} else {
+		while (*first && *second && count) {
+			if( *first != *second)
+				break;
+			first++;
+			second++;
+			count--;
+		}
+		return *first == *second;
+	}
+
+}
+
+int strequal_icase(const char *first, const char *second)
+{
+	if (ignore_case) {
+		while (*first && *second) {
+			if( toupper(*first) != toupper(*second))
+				break;
+			first++;
+			second++;
+		}
+		return toupper(*first) == toupper(*second);
+	} else {
+		while (*first && *second) {
+			if( *first != *second)
+				break;
+			first++;
+			second++;
+		}
+		return *first == *second;
+	}
+}
+
 inline int git_fnmatch(const char *pattern, const char *string,
 		       int flags, int prefix)
 {
@@ -626,11 +671,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 {
-- 
1.7.2.5
Previous: Duy NguyenNext: Duy Nguyen
Message 6 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.