Andrew's git
/
gitweb.git
/ diff
summary
|
log
|
commit
| diff |
tree
commit
grep
author
committer
pickaxe
?
re
object_array: factor out slopbuf-freeing logic
author
Jeff King
<peff@peff.net>
Wed, 15 Oct 2014 22:34:19 +0000
(18:34 -0400)
committer
Junio C Hamano
<gitster@pobox.com>
Thu, 16 Oct 2014 17:10:36 +0000
(10:10 -0700)
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>
object.c
patch
|
blob
|
history
raw
|
patch
|
inline
| side by side (parent:
50a7177
)
diff --git
a/object.c
b/object.c
index ca9d790f4d2b0f30ff585df7a6f8edf515e40a20..60f4864632870a413da989c6380b3fb1316def67 100644
(file)
--- a/
object.c
+++ b/
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,
object_array_each_func_t want, void *cb_data)
{
void object_array_filter(struct object_array *array,
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];
dst++;
} else {
objects[dst] = objects[src];
dst++;
} else {
- if (objects[src].name != object_array_slopbuf)
- free(objects[src].name);
+ object_array_release_entry(&objects[src]);
}
}
array->nr = dst;
}
}
array->nr = dst;
@@
-400,8
+409,7
@@
void object_array_remove_duplicates(struct object_array *array)
objects[array->nr] = objects[src];
array->nr++;
} else {
objects[array->nr] = objects[src];
array->nr++;
} else {
- if (objects[src].name != object_array_slopbuf)
- free(objects[src].name);
+ object_array_release_entry(&objects[src]);
}
}
}
}
}
}