From: Duy Nguyen <pclouds@gmail.com>
To: Fredrik Gustafsson <iveqy@iveqy.com>
Cc: gitster@pobox.com, git@vger.kernel.org
Subject: Re: [PATCH] Replace strcmp_icase with strequal_icase
Date: Sat, 9 Mar 2013 17:21:55 +0700 [thread overview]
Message-ID: <20130309102155.GA11616@lanh> (raw)
In-Reply-To: <1362818574-16873-1-git-send-email-iveqy@iveqy.com>
On Sat, Mar 09, 2013 at 09:42:54AM +0100, Fredrik Gustafsson wrote:
> 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
I tested a slightly different version that checks ignore_case, inlines
if possible and replaces one more strncmp_icase call site (the top
call site in webkit.git). The numbers are impressive (well not as
impressive as yours, but I guess it depends on the actual .gitignore
patterns). On top of my 3/3
before after
user 0m0.508s 0m0.392s
user 0m0.511s 0m0.394s
user 0m0.513s 0m0.405s
user 0m0.516s 0m0.407s
user 0m0.516s 0m0.407s
user 0m0.518s 0m0.410s
user 0m0.519s 0m0.412s
user 0m0.524s 0m0.415s
user 0m0.527s 0m0.415s
user 0m0.534s 0m0.417s
I still need to run the test suite. Then maybe reroll my series with
this.
-- 8< --
diff --git a/dir.c b/dir.c
index 2a91d14..6a9b4b7 100644
--- a/dir.c
+++ b/dir.c
@@ -21,6 +21,24 @@ static int read_directory_recursive(struct dir_struct *dir, const char *path, in
int check_only, const struct path_simplify *simplify);
static int get_dtype(struct dirent *de, const char *path, int len);
+static inline strnequal_icase(const char *first, const char *second, int length)
+{
+ if (ignore_case) {
+ while (length && toupper(*first) == toupper(*second)) {
+ first++;
+ second++;
+ length--;
+ }
+ } else {
+ while (length && *first == *second) {
+ first++;
+ second++;
+ length--;
+ }
+ }
+ return length == 0;
+}
+
inline int git_fnmatch(const char *pattern, const char *string,
int flags, int prefix)
{
@@ -611,11 +629,11 @@ int match_basename(const char *basename, int basenamelen,
{
if (prefix == patternlen) {
if (patternlen == basenamelen &&
- !strncmp_icase(pattern, basename, patternlen))
+ strnequal_icase(pattern, basename, patternlen))
return 1;
} else if (flags & EXC_FLAG_ENDSWITH) {
if (patternlen - 1 <= basenamelen &&
- !strncmp_icase(pattern + 1,
+ strnequal_icase(pattern + 1,
basename + basenamelen - patternlen + 1,
patternlen - 1))
return 1;
@@ -649,7 +667,7 @@ int match_pathname(const char *pathname, int pathlen,
*/
if (pathlen < baselen + 1 ||
(baselen && pathname[baselen] != '/') ||
- (baselen && strncmp_icase(pathname, base, baselen)))
+ (baselen && !strnequal_icase(pathname, base, baselen)))
return 0;
namelen = baselen ? pathlen - baselen - 1 : pathlen;
@@ -663,7 +681,7 @@ int match_pathname(const char *pathname, int pathlen,
if (prefix > namelen)
return 0;
- if (strncmp_icase(pattern, name, prefix))
+ if (!strnequal_icase(pattern, name, prefix))
return 0;
pattern += prefix;
name += prefix;
-- 8< --
next prev parent reply other threads:[~2013-03-09 10:22 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-03-09 8:42 [PATCH] Replace strcmp_icase with strequal_icase Fredrik Gustafsson
2013-03-09 8:57 ` Fredrik Gustafsson
2013-03-09 10:21 ` Duy Nguyen [this message]
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=20130309102155.GA11616@lanh \
--to=pclouds@gmail.com \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=iveqy@iveqy.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).