Re: [PATCH] Replace strcmp_icase with strequal_icase
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