diff options
author | Vicent Marti <tanoku@gmail.com> | 2013-08-14 12:28:01 +0400 |
---|---|---|
committer | Vicent Marti <tanoku@gmail.com> | 2013-08-14 12:28:01 +0400 |
commit | 67591c8cd8d55e6f3218f1a734385c845459e1ff (patch) | |
tree | efd5a6d78aab89b2be399216668cfcf886e380cf /src/sha1_lookup.c | |
parent | 2af9bcb2dbb47adafa7eecbf41ff113da7fa9d1b (diff) |
sha1_lookup: do not use the "experimental" lookup mode
Diffstat (limited to 'src/sha1_lookup.c')
-rw-r--r-- | src/sha1_lookup.c | 24 |
1 files changed, 23 insertions, 1 deletions
diff --git a/src/sha1_lookup.c b/src/sha1_lookup.c index b7e66cc69..8aca86335 100644 --- a/src/sha1_lookup.c +++ b/src/sha1_lookup.c @@ -9,6 +9,7 @@ #include "sha1_lookup.h" #include "common.h" +#include "oid.h" /* * Conventional binary search loop looks like this: @@ -123,7 +124,7 @@ int sha1_entry_pos(const void *table, lov = (lov << 8) | lo_key[ofs_0+1]; kyv = (kyv << 8) | key[ofs_0+1]; } - assert(lov < hiv); + assert(lov <= hiv); if (kyv < lov) return -1 - lo; @@ -176,3 +177,24 @@ int sha1_entry_pos(const void *table, } while (lo < hi); return -((int)lo)-1; } + +int sha1_position(const void *table, + size_t stride, + unsigned lo, unsigned hi, + const unsigned char *key) +{ + do { + unsigned mi = (lo + hi) / 2; + int cmp = git_oid__cmp(table + mi * stride, (git_oid *)key); + + if (!cmp) + return mi; + + if (cmp > 0) + hi = mi; + else + lo = mi+1; + } while (lo < hi); + + return -((int)lo)-1; +} |