summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeff King <peff@peff.net>2017-08-09 16:54:07 -0400
committerJeff King <peff@peff.net>2017-08-09 16:54:22 -0400
commitc9b1e6469e736dd6c17e83c451ae3175612dacab (patch)
treef78c0ac1d50ac819ec0858c0d494584b52f6cde8
parenta9d6b9d529daa920b558ee3f34151422d10bc95e (diff)
downloadlibgit2-peff/hashcmp-is-memcmp.tar.gz
oid: use memcmp in git_oid__hashcmppeff/hashcmp-is-memcmp
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@0b006014c87f400bd9a86267ed30fd3e7b383884.
-rw-r--r--src/oid.h9
1 files changed, 1 insertions, 8 deletions
diff --git a/src/oid.h b/src/oid.h
index 922a2a347..ca6c92cfd 100644
--- a/src/oid.h
+++ b/src/oid.h
@@ -22,14 +22,7 @@ char *git_oid_allocfmt(const git_oid *id);
GIT_INLINE(int) git_oid__hashcmp(const unsigned char *sha1, const unsigned char *sha2)
{
- int i;
-
- for (i = 0; i < GIT_OID_RAWSZ; i++, sha1++, sha2++) {
- if (*sha1 != *sha2)
- return *sha1 - *sha2;
- }
-
- return 0;
+ return memcmp(sha1, sha2, GIT_OID_RAWSZ);
}
/*