aboutsummaryrefslogtreecommitdiff
path: root/builtin
diff options
context:
space:
mode:
authorRené Scharfe <l.s.r@web.de>2017-02-10 21:03:30 +0100
committerJunio C Hamano <gitster@pobox.com>2017-02-13 12:06:10 -0800
commit96f6d3f61ad02ef2fd0393765207233845a7c7e0 (patch)
tree5aea76d086b7c1ab0d2131f743d12c3d3fff69d8 /builtin
parent7b4158a8d8d027491e6e2f7eff3789bd25e093d5 (diff)
downloadgit-96f6d3f61ad02ef2fd0393765207233845a7c7e0.tar.gz
git-96f6d3f61ad02ef2fd0393765207233845a7c7e0.tar.xz
ls-files: move only kept cache entries in prune_cache()
prune_cache() first identifies those entries at the start of the sorted array that can be discarded. Then it moves the rest of the entries up. Last it identifies the unwanted trailing entries among the moved ones and cuts them off. Change the order: Identify both start *and* end of the range to keep first and then move only those entries to the top. The resulting code is slightly shorter and a bit more efficient. Signed-off-by: Rene Scharfe <l.s.r@web.de> Reviewed-by: Brandon Williams <bmwill@google.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'builtin')
-rw-r--r--builtin/ls-files.c9
1 files changed, 4 insertions, 5 deletions
diff --git a/builtin/ls-files.c b/builtin/ls-files.c
index 18105ec7e..1c0f057d0 100644
--- a/builtin/ls-files.c
+++ b/builtin/ls-files.c
@@ -379,10 +379,7 @@ static void prune_cache(const char *prefix, size_t prefixlen)
pos = cache_name_pos(prefix, prefixlen);
if (pos < 0)
pos = -pos-1;
- memmove(active_cache, active_cache + pos,
- (active_nr - pos) * sizeof(struct cache_entry *));
- active_nr -= pos;
- first = 0;
+ first = pos;
last = active_nr;
while (last > first) {
int next = (last + first) >> 1;
@@ -393,7 +390,9 @@ static void prune_cache(const char *prefix, size_t prefixlen)
}
last = next;
}
- active_nr = last;
+ memmove(active_cache, active_cache + pos,
+ (last - pos) * sizeof(struct cache_entry *));
+ active_nr = last - pos;
}
/*