From: Dmitry Potapov Date: Thu, 28 Apr 2011 09:32:56 GMT Subject: Re: [PATCH] git gc: Speed it up by 18% via faster hash comparisons Message-ID: In-Reply-To: <20110427231748.GA26632@elie> 2011/4/28 Jonathan Nieder : > > Hm.  This would be very sensitive to the compiler, since a too-smart > optimizer could take this loop and rewrite it back to memcmp!  So I > wonder if it's possible to convey this to the compiler more precisely: > >        return memcmp_probably_differs_early(sha1, sha2, 20); > > E.g., how would something like > >        const unsigned int *start1 = (const unsigned int *) sha1; >        const unsigned int *start2 = (const unsigned int *) sha2; > >        if (likely(*start1 != *start2)) { >                if (*start1 < *start2) It can be a problem with unalligned access. So, IMHO, it is better to use get_be32 here:        unsigned start1 = get_be32(sha1);        unsigned start2 = get_be32(sha2);        if (likely(start1 != start2)) {                if (start1 < start2) ... Dmitry