From: Pekka Enberg Date: Thu, 28 Apr 2011 12:12:13 GMT Subject: Re: [PATCH] git gc: Speed it up by 18% via faster hash comparisons Message-ID: <4DB9599D.3010208@cs.helsinki.fi> In-Reply-To: On 4/28/11 2:59 PM, Erik Faye-Lund wrote: > So my preference is still something like this. Call me conservative ;) > > diff --git a/cache.h b/cache.h > index c730c58..8bc03c6 100644 > --- a/cache.h > +++ b/cache.h > @@ -681,13 +681,17 @@ 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); > + /* early out for fast mis-match */ > + if (*sha1 != *sha2) > + return *sha1 - *sha2; > + > + return memcmp(sha1 + 1, sha2 + 1, 19); > } > -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) > { Yup, might be the most reasonable thing to do if it still speeds things up. Pekka