diff options
author | Michael Haggerty <mhagger@alum.mit.edu> | 2013-05-25 11:08:08 +0200 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2013-05-28 09:25:01 -0700 |
commit | aeb4a51ef82c71c9a65d11f77aeedb53bea0e983 (patch) | |
tree | 1a656baf48771c3a74dfc8d3c0775cff031fcb53 /object.c | |
parent | ff5f5f268fd36b6db059c06d124305866ecaa6ce (diff) | |
download | git-aeb4a51ef82c71c9a65d11f77aeedb53bea0e983.tar.gz |
object_array: add function object_array_filter()
Add a function that allows unwanted entries in an object_array to be
removed. This encapsulation is a step towards giving object_array
ownership of its entries' name memory.
Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'object.c')
-rw-r--r-- | object.c | 16 |
1 files changed, 16 insertions, 0 deletions
@@ -278,6 +278,22 @@ void add_object_array_with_mode(struct object *obj, const char *name, struct obj array->nr = ++nr; } +void object_array_filter(struct object_array *array, + object_array_each_func_t want, void *cb_data) +{ + unsigned nr = array->nr, src, dst; + struct object_array_entry *objects = array->objects; + + for (src = dst = 0; src < nr; src++) { + if (want(&objects[src], cb_data)) { + if (src != dst) + objects[dst] = objects[src]; + dst++; + } + } + array->nr = dst; +} + void object_array_remove_duplicates(struct object_array *array) { unsigned int ref, src, dst; |