Skip to content

Commit 96f6d3f

Browse files
rscharfegitster
authored andcommitted
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 <[email protected]> Reviewed-by: Brandon Williams <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 7b4158a commit 96f6d3f

File tree

1 file changed

+4
-5
lines changed

1 file changed

+4
-5
lines changed

builtin/ls-files.c

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -379,10 +379,7 @@ static void prune_cache(const char *prefix, size_t prefixlen)
379379
pos = cache_name_pos(prefix, prefixlen);
380380
if (pos < 0)
381381
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;
386383
last = active_nr;
387384
while (last > first) {
388385
int next = (last + first) >> 1;
@@ -393,7 +390,9 @@ static void prune_cache(const char *prefix, size_t prefixlen)
393390
}
394391
last = next;
395392
}
396-
active_nr = last;
393+
memmove(active_cache, active_cache + pos,
394+
(last - pos) * sizeof(struct cache_entry *));
395+
active_nr = last - pos;
397396
}
398397

399398
/*

0 commit comments

Comments
 (0)