Commit 59547ce7 by Vicent Marti

oid: Helper for old-school hashcmp

parent e2164da5
...@@ -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
...@@ -187,7 +187,7 @@ int sha1_position(const void *table, ...@@ -187,7 +187,7 @@ int sha1_position(const void *table,
do { do {
unsigned mi = (lo + hi) / 2; unsigned mi = (lo + hi) / 2;
int cmp = git_oid__cmp((git_oid *)(base + mi * stride), (git_oid *)key); int cmp = git_oid__hashcmp(base + mi * stride, key);
if (!cmp) if (!cmp)
return mi; return mi;
......
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