summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLibravatar Junio C Hamano <gitster@pobox.com>2008-05-08 20:05:43 -0700
committerLibravatar Junio C Hamano <gitster@pobox.com>2008-05-08 20:05:43 -0700
commit4c4d3ac746922886ba75d0aa1114c6ad96788c1a (patch)
treeb323fa6d58bc78d5ecd1ff9252dda41c15aa0948
parentcompat-util: avoid macro redefinition warning (diff)
parentOptimize match_pathspec() to avoid fnmatch() (diff)
downloadtgif-4c4d3ac746922886ba75d0aa1114c6ad96788c1a.tar.xz
Merge branch 'lt/dirmatch-optim'
* lt/dirmatch-optim: Optimize match_pathspec() to avoid fnmatch()
-rw-r--r--dir.c22
1 files changed, 20 insertions, 2 deletions
diff --git a/dir.c b/dir.c
index d79762c7c0..9501476ecd 100644
--- a/dir.c
+++ b/dir.c
@@ -52,6 +52,11 @@ int common_prefix(const char **pathspec)
return prefix;
}
+static inline int special_char(unsigned char c1)
+{
+ return !c1 || c1 == '*' || c1 == '[' || c1 == '?';
+}
+
/*
* Does 'match' matches the given name?
* A match is found if
@@ -69,14 +74,27 @@ static int match_one(const char *match, const char *name, int namelen)
int matchlen;
/* If the match was just the prefix, we matched */
- matchlen = strlen(match);
- if (!matchlen)
+ if (!*match)
return MATCHED_RECURSIVELY;
+ for (;;) {
+ unsigned char c1 = *match;
+ unsigned char c2 = *name;
+ if (special_char(c1))
+ break;
+ if (c1 != c2)
+ return 0;
+ match++;
+ name++;
+ namelen--;
+ }
+
+
/*
* If we don't match the matchstring exactly,
* we need to match by fnmatch
*/
+ matchlen = strlen(match);
if (strncmp(match, name, matchlen))
return !fnmatch(match, name, 0) ? MATCHED_FNMATCH : 0;