Skip to content

Commit 93921b0

Browse files
committed
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>
1 parent eb41775 commit 93921b0

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

dir.c

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -592,11 +592,25 @@ void path_exclude_check_clear(struct path_exclude_check *check)
592592
strbuf_release(&check->path);
593593
}
594594

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+
*/
595603
int path_excluded(struct path_exclude_check *check, struct cache_entry *ce)
596604
{
597605
int i, dtype;
598606
struct strbuf *path = &check->path;
599607

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+
600614
strbuf_setlen(path, 0);
601615
for (i = 0; ce->name[i]; i++) {
602616
int ch = ce->name[i];
@@ -608,6 +622,10 @@ int path_excluded(struct path_exclude_check *check, struct cache_entry *ce)
608622
}
609623
strbuf_addch(path, ch);
610624
}
625+
626+
/* An entry in the index; cannot be a directory with subentries */
627+
strbuf_setlen(path, 0);
628+
611629
dtype = ce_to_dtype(ce);
612630
return excluded(check->dir, ce->name, &dtype);
613631
}

0 commit comments

Comments
 (0)