From: Junio C Hamano Date: Wed, 27 Apr 2011 23:32:12 GMT Subject: Re: [PATCH] git gc: Speed it up by 18% via faster hash comparisons Message-ID: <7voc3r5kzn.fsf@alter.siamese.dyndns.org> In-Reply-To: <20110427225114.GA16765@elte.hu> Ingo Molnar writes: > +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) { > + if (*sha1 < *sha2) > + return -1; > + return +1; > + } > + } > + > + return 0; This is very unfortunate, as it is so trivially correct and we shouldn't have to do it. If the compiler does not use a good inlined memcmp(), this patch may fly, but I fear it may hurt other compilers, no? > +static inline int is_null_sha1(const unsigned char *sha1) > { > - return memcmp(sha1, sha2, 20); > + const unsigned long long *sha1_64 = (void *)sha1; > + const unsigned int *sha1_32 = (void *)sha1; Can everybody do unaligned accesses just fine?