summaryrefslogtreecommitdiff
path: root/ref-filter.c
diff options
context:
space:
mode:
authorJeff King <peff@peff.net>2018-04-06 18:59:45 (GMT)
committerJunio C Hamano <gitster@pobox.com>2018-04-08 21:14:46 (GMT)
commit427cbc9dbfeb7c96bb1d5d9ace722353e2a5438e (patch)
tree744ac05e882b68aefcaabc345a28672effb08c12 /ref-filter.c
parent0ffaa00f453978bffc4ff0f8a45ea0a52549e7cd (diff)
downloadgit-427cbc9dbfeb7c96bb1d5d9ace722353e2a5438e.zip
git-427cbc9dbfeb7c96bb1d5d9ace722353e2a5438e.tar.gz
git-427cbc9dbfeb7c96bb1d5d9ace722353e2a5438e.tar.bz2
ref-filter: factor ref_array pushing into its own function
In preparation for callers constructing their own ref_array structs, let's move our own internal push operation into its own function. While we're at it, we can replace REALLOC_ARRAY() with ALLOC_GROW(), which should give the growth operation amortized linear complexity (as opposed to growing by one, which is potentially quadratic, though in-place realloc growth often makes this faster in practice). Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'ref-filter.c')
-rw-r--r--ref-filter.c16
1 files changed, 13 insertions, 3 deletions
diff --git a/ref-filter.c b/ref-filter.c
index c1c3cc9..6e9328b 100644
--- a/ref-filter.c
+++ b/ref-filter.c
@@ -1840,6 +1840,18 @@ static struct ref_array_item *new_ref_array_item(const char *refname,
return ref;
}
+struct ref_array_item *ref_array_push(struct ref_array *array,
+ const char *refname,
+ const struct object_id *oid)
+{
+ struct ref_array_item *ref = new_ref_array_item(refname, oid);
+
+ ALLOC_GROW(array->items, array->nr + 1, array->alloc);
+ array->items[array->nr++] = ref;
+
+ return ref;
+}
+
static int ref_kind_from_refname(const char *refname)
{
unsigned int i;
@@ -1930,13 +1942,11 @@ static int ref_filter_handler(const char *refname, const struct object_id *oid,
* to do its job and the resulting list may yet to be pruned
* by maxcount logic.
*/
- ref = new_ref_array_item(refname, oid);
+ ref = ref_array_push(ref_cbdata->array, refname, oid);
ref->commit = commit;
ref->flag = flag;
ref->kind = kind;
- REALLOC_ARRAY(ref_cbdata->array->items, ref_cbdata->array->nr + 1);
- ref_cbdata->array->items[ref_cbdata->array->nr++] = ref;
return 0;
}