Skip to content

Commit be6754c

Browse files
mhaggergitster
authored andcommitted
revision: use object_array_filter() in implementation of gc_boundary()
Use object_array_filter(), which will soon be made smarter about cleaning up discarded entries properly. Also add a function comment. Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent aeb4a51 commit be6754c

1 file changed

Lines changed: 15 additions & 17 deletions

File tree

revision.c

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2435,25 +2435,23 @@ static struct commit *get_revision_1(struct rev_info *revs)
24352435
return NULL;
24362436
}
24372437

2438-
static void gc_boundary(struct object_array *array)
2438+
/*
2439+
* Return true for entries that have not yet been shown. (This is an
2440+
* object_array_each_func_t.)
2441+
*/
2442+
static int entry_unshown(struct object_array_entry *entry, void *cb_data_unused)
24392443
{
2440-
unsigned nr = array->nr;
2441-
unsigned alloc = array->alloc;
2442-
struct object_array_entry *objects = array->objects;
2444+
return !(entry->item->flags & SHOWN);
2445+
}
24432446

2444-
if (alloc <= nr) {
2445-
unsigned i, j;
2446-
for (i = j = 0; i < nr; i++) {
2447-
if (objects[i].item->flags & SHOWN)
2448-
continue;
2449-
if (i != j)
2450-
objects[j] = objects[i];
2451-
j++;
2452-
}
2453-
for (i = j; i < nr; i++)
2454-
objects[i].item = NULL;
2455-
array->nr = j;
2456-
}
2447+
/*
2448+
* If array is on the verge of a realloc, garbage-collect any entries
2449+
* that have already been shown to try to free up some space.
2450+
*/
2451+
static void gc_boundary(struct object_array *array)
2452+
{
2453+
if (array->nr == array->alloc)
2454+
object_array_filter(array, entry_unshown, NULL);
24572455
}
24582456

24592457
static void create_boundary_commit_list(struct rev_info *revs)

0 commit comments

Comments
 (0)