git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Fredrik Gustafsson <iveqy@iveqy.com>
To: gitster@pobox.com
Cc: git@vger.kernel.org, iveqy@iveqy.com, pclouds@gmail.com
Subject: [PATCH] Replace strcmp_icase with strequal_icase
Date: Sat,  9 Mar 2013 09:42:54 +0100	[thread overview]
Message-ID: <1362818574-16873-1-git-send-email-iveqy@iveqy.com> (raw)

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

             reply	other threads:[~2013-03-09  8:43 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-03-09  8:42 Fredrik Gustafsson [this message]
2013-03-09  8:57 ` [PATCH] Replace strcmp_icase with strequal_icase Fredrik Gustafsson
2013-03-09 10:21 ` Duy Nguyen
2013-03-09 10:40 ` Duy Nguyen
2013-03-09 10:54   ` Duy Nguyen
2013-03-09 11:08     ` Fredrik Gustafsson
2013-03-09 12:05       ` Duy Nguyen
2013-03-09 12:22         ` Fredrik Gustafsson
2013-03-09 12:40           ` Duy Nguyen

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1362818574-16873-1-git-send-email-iveqy@iveqy.com \
    --to=iveqy@iveqy.com \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=pclouds@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).