summaryrefslogtreecommitdiff
path: root/object.h
diff options
context:
space:
mode:
authorMichael Haggerty <mhagger@alum.mit.edu>2013-05-25 11:08:10 +0200
committerJunio C Hamano <gitster@pobox.com>2013-05-28 09:25:01 -0700
commit1506510c170d23b8f769757dc81904f334c40281 (patch)
treec5f89d862073b5aca88dd082a08591d097cbb8bb /object.h
parentbe6754c67f5aff02e9528116d06890391524f48e (diff)
downloadgit-1506510c170d23b8f769757dc81904f334c40281.tar.gz
object_array_remove_duplicates(): rewrite to reduce copying
The old version copied one entry to its destination position, then deleted any matching entries from the tail of the array. This required the tail of the array to be copied multiple times. It didn't affect the complexity of the algorithm because the whole tail has to be searched through anyway. But all the copying was unnecessary. Instead, check for the existence of an entry with the same name in the *head* of the list before copying an entry to its final position. This way each entry has to be copied at most one time. Extract a helper function contains_name() to do a bit of the work. Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'object.h')
-rw-r--r--object.h6
1 files changed, 5 insertions, 1 deletions
diff --git a/object.h b/object.h
index 0d39ff4f9d..6c1c27fba6 100644
--- a/object.h
+++ b/object.h
@@ -96,7 +96,11 @@ typedef int (*object_array_each_func_t)(struct object_array_entry *, void *);
void object_array_filter(struct object_array *array,
object_array_each_func_t want, void *cb_data);
-void object_array_remove_duplicates(struct object_array *);
+/*
+ * Remove from array all but the first entry with a given name.
+ * Warning: this function uses an O(N^2) algorithm.
+ */
+void object_array_remove_duplicates(struct object_array *array);
void clear_object_flags(unsigned flags);