Merge branch 'rs/ls-files-partial-optim'
"ls-files" run with pathspec has been micro-optimized to avoid having to memmove(3) unnecessary bytes. * rs/ls-files-partial-optim: ls-files: move only kept cache entries in prune_cache() ls-files: pass prefix length explicitly to prune_cache()
This commit is contained in:
@ -369,28 +369,30 @@ static void show_files(struct dir_struct *dir)
|
|||||||
/*
|
/*
|
||||||
* Prune the index to only contain stuff starting with "prefix"
|
* Prune the index to only contain stuff starting with "prefix"
|
||||||
*/
|
*/
|
||||||
static void prune_cache(const char *prefix)
|
static void prune_cache(const char *prefix, size_t prefixlen)
|
||||||
{
|
{
|
||||||
int pos = cache_name_pos(prefix, max_prefix_len);
|
int pos;
|
||||||
unsigned int first, last;
|
unsigned int first, last;
|
||||||
|
|
||||||
|
if (!prefix)
|
||||||
|
return;
|
||||||
|
pos = cache_name_pos(prefix, prefixlen);
|
||||||
if (pos < 0)
|
if (pos < 0)
|
||||||
pos = -pos-1;
|
pos = -pos-1;
|
||||||
memmove(active_cache, active_cache + pos,
|
first = pos;
|
||||||
(active_nr - pos) * sizeof(struct cache_entry *));
|
|
||||||
active_nr -= pos;
|
|
||||||
first = 0;
|
|
||||||
last = active_nr;
|
last = active_nr;
|
||||||
while (last > first) {
|
while (last > first) {
|
||||||
int next = (last + first) >> 1;
|
int next = (last + first) >> 1;
|
||||||
const struct cache_entry *ce = active_cache[next];
|
const struct cache_entry *ce = active_cache[next];
|
||||||
if (!strncmp(ce->name, prefix, max_prefix_len)) {
|
if (!strncmp(ce->name, prefix, prefixlen)) {
|
||||||
first = next+1;
|
first = next+1;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
last = next;
|
last = next;
|
||||||
}
|
}
|
||||||
active_nr = last;
|
memmove(active_cache, active_cache + pos,
|
||||||
|
(last - pos) * sizeof(struct cache_entry *));
|
||||||
|
active_nr = last - pos;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -641,8 +643,7 @@ int cmd_ls_files(int argc, const char **argv, const char *cmd_prefix)
|
|||||||
show_killed || show_modified || show_resolve_undo))
|
show_killed || show_modified || show_resolve_undo))
|
||||||
show_cached = 1;
|
show_cached = 1;
|
||||||
|
|
||||||
if (max_prefix)
|
prune_cache(max_prefix, max_prefix_len);
|
||||||
prune_cache(max_prefix);
|
|
||||||
if (with_tree) {
|
if (with_tree) {
|
||||||
/*
|
/*
|
||||||
* Basic sanity check; show-stages and show-unmerged
|
* Basic sanity check; show-stages and show-unmerged
|
||||||
|
Reference in New Issue
Block a user