sha1-lookup: switch hard-coded constants to the_hash_algo
Switch a hard-coded 18 to be a reference to the_hash_algo. Rename the sha1 parameter to be called hash instead. Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
brian m. carlson committed
Aug 18, 2019 at 20:04 UTC
e84f3572bd9160f281629bb2a098b35ea87c10e1
1 file changed
+4
-4
sha1-lookup.c
+4
-4
@@ -50,7 +50,7 @@ static uint32_t take2(const unsigned char *sha1)
50
* The sha1 of element i (between 0 and nr - 1) should be returned
51
* by "fn(i, table)".
52
*/
53
-int sha1_pos(const unsigned char *sha1, void *table, size_t nr,
53
+int sha1_pos(const unsigned char *hash, void *table, size_t nr,
54
sha1_access_fn fn)
55
{
56
size_t hi = nr;
@@ -63,10 +63,10 @@ int sha1_pos(const unsigned char *sha1, void *table, size_t nr,
63
if (nr != 1) {
64
size_t lov, hiv, miv, ofs;
65
66
- for (ofs = 0; ofs < 18; ofs += 2) {
66
+ for (ofs = 0; ofs < the_hash_algo->rawsz - 2; ofs += 2) {
67
lov = take2(fn(0, table) + ofs);
68
hiv = take2(fn(nr - 1, table) + ofs);
69
- miv = take2(sha1 + ofs);
69
+ miv = take2(hash + ofs);
70
if (miv < lov)
71
return -1;
72
if (hiv < miv)
@@ -88,7 +88,7 @@ int sha1_pos(const unsigned char *sha1, void *table, size_t nr,
88
89
do {
90
int cmp;
91
- cmp = hashcmp(fn(mi, table), sha1);
91
+ cmp = hashcmp(fn(mi, table), hash);
92
if (!cmp)
93
return mi;
94
if (cmp > 0)