summaryrefslogtreecommitdiff
path: root/oid-array.c
diff options
context:
space:
mode:
Diffstat (limited to 'oid-array.c')
-rw-r--r--oid-array.c27
1 files changed, 12 insertions, 15 deletions
diff --git a/oid-array.c b/oid-array.c
index 8657a5cedf..73ba76e9e9 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,23 +14,24 @@ 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;
}
-static const unsigned char *sha1_access(size_t index, void *table)
+static const struct object_id *oid_access(size_t index, const void *table)
{
- struct object_id *array = table;
- return array[index].hash;
+ const struct object_id *array = table;
+ return &array[index];
}
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 oid_pos(oid, array->oid, array->nr, oid_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;
}