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>
Michael Haggerty committed
May 25, 2013 at 11:08 UTC
be6754c67f5aff02e9528116d06890391524f48e
1 file changed
+15
-17
revision.c
+15
-17
@@ -2435,25 +2435,23 @@ static struct commit *get_revision_1(struct rev_info *revs)
2435
return NULL;
2436
}
2437
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)
2443
{
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
+}
2446
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);
2455
}
2456
2457
static void create_boundary_commit_list(struct rev_info *revs)