Re: [PATCH] git gc: Speed it up by 18% via faster hash comparisons
- From
Junio C Hamano <gitster@pobox.com>
- Date
- Apr 27, 2011, 23:32 UTC
- Message-ID
- <7voc3r5kzn.fsf@alter.siamese.dyndns.org>
- In-Reply-To
- <20110427225114.GA16765@elte.hu>
Ingo Molnar <mingo@elte.hu> writes:
Show 14 quoted lines
> +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?
Show 5 quoted lines
> +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?