ls-files -i: micro-optimize path_excluded()
As we know a caller that does not recurse is calling us in the index order, we can remember the last directory we found to be excluded and see if the path we are looking at is still inside it, in which case we can just answer that it is excluded. Signed-off-by: Junio C Hamano <gitster@pobox.com>
Junio C Hamano committed
Jun 1, 2012 at 12:22 UTC
93921b07e985de38f7af6689d81e5c7dfb3f8aa0
1 file changed
+18
dir.c
+18
@@ -592,11 +592,25 @@ void path_exclude_check_clear(struct path_exclude_check *check)
592
strbuf_release(&check->path);
593
}
594
595
+/*
596
+ * Is the ce->name excluded? This is for a caller like show_files() that
597
+ * do not honor directory hierarchy and iterate through paths that are
598
+ * possibly in an ignored directory.
599
+ *
600
+ * A path to a directory known to be excluded is left in check->path to
601
+ * optimize for repeated checks for files in the same excluded directory.
602
+ */
603
int path_excluded(struct path_exclude_check *check, struct cache_entry *ce)
604
{
605
int i, dtype;
606
struct strbuf *path = &check->path;
607
608
+ if (path->len &&
609
+ path->len <= ce_namelen(ce) &&
610
+ !memcmp(ce->name, path->buf, path->len) &&
611
+ (!ce->name[path->len] || ce->name[path->len] == '/'))
612
+ return 1;
613
+
614
strbuf_setlen(path, 0);
615
for (i = 0; ce->name[i]; i++) {
616
int ch = ce->name[i];
@@ -608,6 +622,10 @@ int path_excluded(struct path_exclude_check *check, struct cache_entry *ce)
622
}
623
strbuf_addch(path, ch);
624
}
625
+
626
+ /* An entry in the index; cannot be a directory with subentries */
627
+ strbuf_setlen(path, 0);
628
+
629
dtype = ce_to_dtype(ce);
630
return excluded(check->dir, ce->name, &dtype);
631
}