summaryrefslogtreecommitdiff
path: root/oid-array.c
diff options
context:
space:
mode:
Diffstat (limited to 'oid-array.c')
-rw-r--r--oid-array.c21
1 files changed, 9 insertions, 12 deletions
diff --git a/oid-array.c b/oid-array.c
index 8657a5cedf..889b311f22 100644
--- a/oid-array.c
+++ b/oid-array.c
@@ -1,6 +1,6 @@
#include "cache.h"
#include "oid-array.h"
-#include "sha1-lookup.h"
+#include "hash-lookup.h"
void oid_array_append(struct oid_array *array, const struct object_id *oid)
{
@@ -14,8 +14,10 @@ static int void_hashcmp(const void *a, const void *b)
return oidcmp(a, b);
}
-static void oid_array_sort(struct oid_array *array)
+void oid_array_sort(struct oid_array *array)
{
+ if (array->sorted)
+ return;
QSORT(array->oid, array->nr, void_hashcmp);
array->sorted = 1;
}
@@ -28,9 +30,8 @@ static const unsigned char *sha1_access(size_t index, void *table)
int oid_array_lookup(struct oid_array *array, const struct object_id *oid)
{
- if (!array->sorted)
- oid_array_sort(array);
- return sha1_pos(oid->hash, array->oid, array->nr, sha1_access);
+ oid_array_sort(array);
+ return hash_pos(oid->hash, array->oid, array->nr, sha1_access);
}
void oid_array_clear(struct oid_array *array)
@@ -64,14 +65,10 @@ int oid_array_for_each_unique(struct oid_array *array,
{
size_t i;
- if (!array->sorted)
- oid_array_sort(array);
+ oid_array_sort(array);
- for (i = 0; i < array->nr; i++) {
- int ret;
- if (i > 0 && oideq(array->oid + i, array->oid + i - 1))
- continue;
- ret = fn(array->oid + i, data);
+ for (i = 0; i < array->nr; i = oid_array_next_unique(array, i)) {
+ int ret = fn(array->oid + i, data);
if (ret)
return ret;
}