object_array: factor out slopbuf-freeing logic
This is not a lot of code, but it's a logical construct that should not need to be repeated (and we are about to add a third repetition). Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>maint
parent
50a71776ab
commit
68f492359e
16
object.c
16
object.c
|
@ -355,6 +355,16 @@ void add_object_array_with_context(struct object *obj, const char *name, struct
|
||||||
add_object_array_with_mode_context(obj, name, array, S_IFINVALID, context);
|
add_object_array_with_mode_context(obj, name, array, S_IFINVALID, context);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Free all memory associated with an entry; the result is
|
||||||
|
* in an unspecified state and should not be examined.
|
||||||
|
*/
|
||||||
|
static void object_array_release_entry(struct object_array_entry *ent)
|
||||||
|
{
|
||||||
|
if (ent->name != object_array_slopbuf)
|
||||||
|
free(ent->name);
|
||||||
|
}
|
||||||
|
|
||||||
void object_array_filter(struct object_array *array,
|
void object_array_filter(struct object_array *array,
|
||||||
object_array_each_func_t want, void *cb_data)
|
object_array_each_func_t want, void *cb_data)
|
||||||
{
|
{
|
||||||
|
@ -367,8 +377,7 @@ void object_array_filter(struct object_array *array,
|
||||||
objects[dst] = objects[src];
|
objects[dst] = objects[src];
|
||||||
dst++;
|
dst++;
|
||||||
} else {
|
} else {
|
||||||
if (objects[src].name != object_array_slopbuf)
|
object_array_release_entry(&objects[src]);
|
||||||
free(objects[src].name);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
array->nr = dst;
|
array->nr = dst;
|
||||||
|
@ -400,8 +409,7 @@ void object_array_remove_duplicates(struct object_array *array)
|
||||||
objects[array->nr] = objects[src];
|
objects[array->nr] = objects[src];
|
||||||
array->nr++;
|
array->nr++;
|
||||||
} else {
|
} else {
|
||||||
if (objects[src].name != object_array_slopbuf)
|
object_array_release_entry(&objects[src]);
|
||||||
free(objects[src].name);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue