pathspec: save the non-wildcard length part

We mark pathspec with wildcards with the field use_wildcard. We could do better by saving the length of the non-wildcard part, which can be used for optimizations such as f9f6e2c (exclude: do strcmp as much as possible before fnmatch - 2012-06-07). Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Nguyễn Thái Ngọc Duy committed Nov 18, 2012 at 16:13 UTC 170260ae90cb6a0fec476e7d970e3ac3e81e98f5
5 files changed +8 -8
builtin/ls-files.c
+1 -1
@@ -337,7 +337,7 @@ void overlay_tree_on_cache(const char *tree_name, const char *prefix)
337 matchbuf[0] = prefix;
338 matchbuf[1] = NULL;
339 init_pathspec(&pathspec, matchbuf);
340 - pathspec.items[0].use_wildcard = 0;
340 + pathspec.items[0].nowildcard_len = pathspec.items[0].len;
341 } else
342 init_pathspec(&pathspec, NULL);
343 if (read_tree(tree, 1, &pathspec))
builtin/ls-tree.c
+1 -1
@@ -168,7 +168,7 @@ int cmd_ls_tree(int argc, const char **argv, const char *prefix)
168
169 init_pathspec(&pathspec, get_pathspec(prefix, argv + 1));
170 for (i = 0; i < pathspec.nr; i++)
171 - pathspec.items[i].use_wildcard = 0;
171 + pathspec.items[i].nowildcard_len = pathspec.items[i].len;
172 pathspec.has_wildcard = 0;
173 tree = parse_tree_indirect(sha1);
174 if (!tree)
cache.h
+1 -1
@@ -482,7 +482,7 @@ struct pathspec {
482 struct pathspec_item {
483 const char *match;
484 int len;
485 - unsigned int use_wildcard:1;
485 + int nowildcard_len;
486 } *items;
487 };
488
dir.c
+3 -3
@@ -230,7 +230,7 @@ static int match_pathspec_item(const struct pathspec_item *item, int prefix,
230 return MATCHED_RECURSIVELY;
231 }
232
233 - if (item->use_wildcard && !fnmatch(match, name, 0))
233 + if (item->nowildcard_len < item->len && !fnmatch(match, name, 0))
234 return MATCHED_FNMATCH;
235
236 return 0;
@@ -1429,8 +1429,8 @@ int init_pathspec(struct pathspec *pathspec, const char **paths)
1429
1430 item->match = path;
1431 item->len = strlen(path);
1432 - item->use_wildcard = !no_wildcard(path);
1433 - if (item->use_wildcard)
1432 + item->nowildcard_len = simple_length(path);
1433 + if (item->nowildcard_len < item->len)
1434 pathspec->has_wildcard = 1;
1435 }
1436
tree-walk.c
+2 -2
@@ -626,7 +626,7 @@ enum interesting tree_entry_interesting(const struct name_entry *entry,
626 &never_interesting))
627 return entry_interesting;
628
629 - if (item->use_wildcard) {
629 + if (item->nowildcard_len < item->len) {
630 if (!fnmatch(match + baselen, entry->path, 0))
631 return entry_interesting;
632
@@ -642,7 +642,7 @@ enum interesting tree_entry_interesting(const struct name_entry *entry,
642 }
643
644 match_wildcards:
645 - if (!item->use_wildcard)
645 + if (item->nowildcard_len == item->len)
646 continue;
647
648 /*