summaryrefslogtreecommitdiff
path: root/cache.h
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2011-05-06 11:00:36 -0700
committerJunio C Hamano <gitster@pobox.com>2011-05-06 11:00:36 -0700
commitefa67bfd16f4260275654bc4194744dd65353350 (patch)
tree4a207225d19d0e5f96d3c1a008a537e196fcbab2 /cache.h
parentac13e7c514d6790cc59041545f26b3f5da543b25 (diff)
parent1a812f3a701969824caf96803e160cbad6050520 (diff)
downloadgit-efa67bfd16f4260275654bc4194744dd65353350.tar.gz
Merge branch 'im/hashcmp-optim'
* im/hashcmp-optim: hashcmp(): inline memcmp() by hand to optimize
Diffstat (limited to 'cache.h')
-rw-r--r--cache.h18
1 files changed, 14 insertions, 4 deletions
diff --git a/cache.h b/cache.h
index 5b896d9845..2b34116624 100644
--- a/cache.h
+++ b/cache.h
@@ -676,14 +676,24 @@ extern char *sha1_pack_name(const unsigned char *sha1);
extern char *sha1_pack_index_name(const unsigned char *sha1);
extern const char *find_unique_abbrev(const unsigned char *sha1, int);
extern const unsigned char null_sha1[20];
-static inline int is_null_sha1(const unsigned char *sha1)
+
+static inline int hashcmp(const unsigned char *sha1, const unsigned char *sha2)
{
- return !memcmp(sha1, null_sha1, 20);
+ int i;
+
+ for (i = 0; i < 20; i++, sha1++, sha2++) {
+ if (*sha1 != *sha2)
+ return *sha1 - *sha2;
+ }
+
+ return 0;
}
-static inline int hashcmp(const unsigned char *sha1, const unsigned char *sha2)
+
+static inline int is_null_sha1(const unsigned char *sha1)
{
- return memcmp(sha1, sha2, 20);
+ return !hashcmp(sha1, null_sha1);
}
+
static inline void hashcpy(unsigned char *sha_dst, const unsigned char *sha_src)
{
memcpy(sha_dst, sha_src, 20);