Skip to content

Commit c9b1e64

Browse files
committed
oid: use memcmp in git_oid__hashcmp
The open-coded version was inherited from git.git. But it turns out it was based on an older version of glibc, whose memcmp was not very optimized. Modern glibc does much better, and some compilers (like gcc 7) can even inline the memcmp into a series of multi-byte xors. Upstream is switching to using memcmp in git/git@0b00601.
1 parent a9d6b9d commit c9b1e64

File tree

1 file changed

+1
-8
lines changed

1 file changed

+1
-8
lines changed

src/oid.h

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,7 @@ char *git_oid_allocfmt(const git_oid *id);
2222

2323
GIT_INLINE(int) git_oid__hashcmp(const unsigned char *sha1, const unsigned char *sha2)
2424
{
25-
int i;
26-
27-
for (i = 0; i < GIT_OID_RAWSZ; i++, sha1++, sha2++) {
28-
if (*sha1 != *sha2)
29-
return *sha1 - *sha2;
30-
}
31-
32-
return 0;
25+
return memcmp(sha1, sha2, GIT_OID_RAWSZ);
3326
}
3427

3528
/*

0 commit comments

Comments
 (0)