summaryrefslogtreecommitdiff
path: root/include/git2/oid.h
diff options
context:
space:
mode:
authorMichael Schubert <schu@schu.io>2012-07-27 10:53:09 +0200
committerMichael Schubert <schu@schu.io>2012-07-29 20:50:58 +0200
commitf6b26e770ffae621408532c5b2c1aae4fa1c9e49 (patch)
tree6d8aceb0bb50223d2f4791e11d6cab171923e0ec /include/git2/oid.h
parent6810ba089a543a2407b1c8824dffa9b4e1d63975 (diff)
downloadlibgit2-f6b26e770ffae621408532c5b2c1aae4fa1c9e49.tar.gz
git_oid_cmp: inline memcmp by hand to optimize
git.git uses an inlined hashcmp function instead of memcmp, since it performes much better when comparing hashes (most hashes compared diverge within the first byte). Measurements and rationale for the curious reader: http://thread.gmane.org/gmane.comp.version-control.git/172286
Diffstat (limited to 'include/git2/oid.h')
-rw-r--r--include/git2/oid.h26
1 files changed, 25 insertions, 1 deletions
diff --git a/include/git2/oid.h b/include/git2/oid.h
index a05b40a37..d6b2d1e7f 100644
--- a/include/git2/oid.h
+++ b/include/git2/oid.h
@@ -136,7 +136,31 @@ GIT_EXTERN(void) git_oid_cpy(git_oid *out, const git_oid *src);
* @param b second oid structure.
* @return <0, 0, >0 if a < b, a == b, a > b.
*/
-GIT_EXTERN(int) git_oid_cmp(const git_oid *a, const git_oid *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;
+
+ for (i = 0; i < GIT_OID_RAWSZ; i++, sha1++, sha2++) {
+ if (*sha1 != *sha2)
+ return *sha1 - *sha2;
+ }
+
+ return 0;
+}
+
+/**
+ * Compare two oid structures for equality
+ *
+ * @param a first oid structure.
+ * @param b second oid structure.
+ * @return true if equal, false otherwise
+ */
+GIT_INLINE(int) git_oid_equal(const git_oid *a, const git_oid *b)
+{
+ return !git_oid_cmp(a, b);
+}
/**
* Compare the first 'len' hexadecimal characters (packets of 4 bits)