On Sat, Jun 16, 2007 at 10:30:22AM -0700, Linus Torvalds wrote: > When adding objects to the object/mode array, we used to have our own > alloc_nr() implementation, rather than use the normal one. > > And since the normal one is arguably a bit nicer (still grows the > allocation exponentially, just not by more-than-doubling it every time), > why not just use it? How about using the new ALLOC_GROW macro to make it even shorter? I also got rid of the aliased variables, which IMO just make it harder to see what's going on. --- object.c | 19 +++++-------------- 1 files changed, 5 insertions(+), 14 deletions(-) diff --git a/object.c b/object.c index 16793d9..064e423 100644 --- a/object.c +++ b/object.c @@ -240,18 +240,9 @@ void add_object_array(struct object *obj, const char *name, struct object_array void add_object_array_with_mode(struct object *obj, const char *name, struct object_array *array, unsigned mode) { - unsigned nr = array->nr; - unsigned alloc = array->alloc; - struct object_array_entry *objects = array->objects; - - if (nr >= alloc) { - alloc = (alloc + 32) * 2; - objects = xrealloc(objects, alloc * sizeof(*objects)); - array->alloc = alloc; - array->objects = objects; - } - objects[nr].item = obj; - objects[nr].name = name; - objects[nr].mode = mode; - array->nr = ++nr; + ALLOC_GROW(array->objects, array->nr, array->alloc); + array->objects[array->nr].item = obj; + array->objects[array->nr].name = name; + array->objects[array->nr].mode = mode; + array->nr++; } - To unsubscribe from this list: send the line "unsubscribe git" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html