commit.c: use the generic "sha1_pos" function for lookup
Refactor binary search in "commit_graft_pos" function: use generic "sha1_pos" function. Signed-off-by: Dmitry S. Dolzhenko <dmitrys.dolzhenko@yandex.ru> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Dmitry S. Dolzhenko committed
Feb 26, 2014 at 22:49 UTC
0a9136f32758a785fe552adc58bba5824f85e5b7
1 file changed
+9
-15
commit.c
+9
-15
@@ -10,6 +10,7 @@
10
#include "mergesort.h"
11
#include "commit-slab.h"
12
#include "prio-queue.h"
13
+#include "sha1-lookup.h"
14
15
static struct commit_extra_header *read_commit_extra_header_lines(const char *buf, size_t len, const char **);
16
@@ -114,23 +115,16 @@ static unsigned long parse_commit_date(const char *buf, const char *tail)
115
static struct commit_graft **commit_graft;
116
static int commit_graft_alloc, commit_graft_nr;
117
118
+static const unsigned char *commit_graft_sha1_access(size_t index, void *table)
119
+{
120
+ struct commit_graft **commit_graft_table = table;
121
+ return commit_graft_table[index]->sha1;
122
+}
123
+
124
static int commit_graft_pos(const unsigned char *sha1)
125
{
119
- int lo, hi;
120
- lo = 0;
121
- hi = commit_graft_nr;
122
- while (lo < hi) {
123
- int mi = (lo + hi) / 2;
124
- struct commit_graft *graft = commit_graft[mi];
125
- int cmp = hashcmp(sha1, graft->sha1);
126
- if (!cmp)
127
- return mi;
128
- if (cmp < 0)
129
- hi = mi;
130
- else
131
- lo = mi + 1;
132
- }
133
- return -lo - 1;
126
+ return sha1_pos(sha1, commit_graft, commit_graft_nr,
127
+ commit_graft_sha1_access);
128
}
129
130
int register_commit_graft(struct commit_graft *graft, int ignore_dups)