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>

René Scharfe committed Feb 10, 2017 at 21:03 UTC 96f6d3f61ad02ef2fd0393765207233845a7c7e0
1 file changed +4 -5
builtin/ls-files.c
+4 -5
@@ -379,10 +379,7 @@ static void prune_cache(const char *prefix, size_t prefixlen)
379 pos = cache_name_pos(prefix, prefixlen);
380 if (pos < 0)
381 pos = -pos-1;
382 - memmove(active_cache, active_cache + pos,
383 - (active_nr - pos) * sizeof(struct cache_entry *));
384 - active_nr -= pos;
385 - first = 0;
382 + first = pos;
383 last = active_nr;
384 while (last > first) {
385 int next = (last + first) >> 1;
@@ -393,7 +390,9 @@ static void prune_cache(const char *prefix, size_t prefixlen)
390 }
391 last = next;
392 }
396 - active_nr = last;
393 + memmove(active_cache, active_cache + pos,
394 + (last - pos) * sizeof(struct cache_entry *));
395 + active_nr = last - pos;
396 }
397
398 /*