Commit d5904eb8 by Vicent Martí

Merge pull request #1782 from libgit2/vmg/no-lookup

Do not use the "experimental" lookup mode
parents 2af9bcb2 59547ce7
...@@ -9,17 +9,8 @@ ...@@ -9,17 +9,8 @@
#include "git2/oid.h" #include "git2/oid.h"
/* GIT_INLINE(int) git_oid__hashcmp(const unsigned char *sha1, const unsigned char *sha2)
* Compare two oid structures.
*
* @param a first oid structure.
* @param b second oid structure.
* @return <0, 0, >0 if a < b, a == b, a > b.
*/
GIT_INLINE(int) git_oid__cmp(const git_oid *a, const git_oid *b)
{ {
const unsigned char *sha1 = a->id;
const unsigned char *sha2 = b->id;
int i; int i;
for (i = 0; i < GIT_OID_RAWSZ; i++, sha1++, sha2++) { for (i = 0; i < GIT_OID_RAWSZ; i++, sha1++, sha2++) {
...@@ -30,4 +21,16 @@ GIT_INLINE(int) git_oid__cmp(const git_oid *a, const git_oid *b) ...@@ -30,4 +21,16 @@ GIT_INLINE(int) git_oid__cmp(const git_oid *a, const git_oid *b)
return 0; return 0;
} }
/*
* Compare two oid structures.
*
* @param a first oid structure.
* @param b second oid structure.
* @return <0, 0, >0 if a < b, a == b, a > b.
*/
GIT_INLINE(int) git_oid__cmp(const git_oid *a, const git_oid *b)
{
return git_oid__hashcmp(a->id, b->id);
}
#endif #endif
...@@ -1110,8 +1110,11 @@ static int pack_entry_find_offset( ...@@ -1110,8 +1110,11 @@ static int pack_entry_find_offset(
short_oid->id[0], short_oid->id[1], short_oid->id[2], lo, hi, p->num_objects); short_oid->id[0], short_oid->id[1], short_oid->id[2], lo, hi, p->num_objects);
#endif #endif
/* Use git.git lookup code */ #ifdef GIT_USE_LOOKUP
pos = sha1_entry_pos(index, stride, 0, lo, hi, p->num_objects, short_oid->id); pos = sha1_entry_pos(index, stride, 0, lo, hi, p->num_objects, short_oid->id);
#else
pos = sha1_position(index, stride, lo, hi, short_oid->id);
#endif
if (pos >= 0) { if (pos >= 0) {
/* An object matching exactly the oid was found */ /* An object matching exactly the oid was found */
......
...@@ -9,6 +9,7 @@ ...@@ -9,6 +9,7 @@
#include "sha1_lookup.h" #include "sha1_lookup.h"
#include "common.h" #include "common.h"
#include "oid.h"
/* /*
* Conventional binary search loop looks like this: * Conventional binary search loop looks like this:
...@@ -123,7 +124,7 @@ int sha1_entry_pos(const void *table, ...@@ -123,7 +124,7 @@ int sha1_entry_pos(const void *table,
lov = (lov << 8) | lo_key[ofs_0+1]; lov = (lov << 8) | lo_key[ofs_0+1];
kyv = (kyv << 8) | key[ofs_0+1]; kyv = (kyv << 8) | key[ofs_0+1];
} }
assert(lov < hiv); assert(lov <= hiv);
if (kyv < lov) if (kyv < lov)
return -1 - lo; return -1 - lo;
...@@ -176,3 +177,26 @@ int sha1_entry_pos(const void *table, ...@@ -176,3 +177,26 @@ int sha1_entry_pos(const void *table,
} while (lo < hi); } while (lo < hi);
return -((int)lo)-1; return -((int)lo)-1;
} }
int sha1_position(const void *table,
size_t stride,
unsigned lo, unsigned hi,
const unsigned char *key)
{
const unsigned char *base = table;
do {
unsigned mi = (lo + hi) / 2;
int cmp = git_oid__hashcmp(base + mi * stride, key);
if (!cmp)
return mi;
if (cmp > 0)
hi = mi;
else
lo = mi+1;
} while (lo < hi);
return -((int)lo)-1;
}
...@@ -15,4 +15,9 @@ int sha1_entry_pos(const void *table, ...@@ -15,4 +15,9 @@ int sha1_entry_pos(const void *table,
unsigned lo, unsigned hi, unsigned nr, unsigned lo, unsigned hi, unsigned nr,
const unsigned char *key); const unsigned char *key);
int sha1_position(const void *table,
size_t stride,
unsigned lo, unsigned hi,
const unsigned char *key);
#endif #endif
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment