From: Florian Weimer Date: Sun, 12 Feb 2006 11:19:23 GMT Subject: Re: [PATCH] Use a hashtable for objects instead of a sorted list Message-ID: <87accwlt8k.fsf@mid.deneb.enyo.de> In-Reply-To: <7virrli9am.fsf@assigned-by-dhcp.cox.net> * Junio C. Hamano: > static int hashtable_index(const unsigned char *sha1) > { > - unsigned int i = *(unsigned int *)sha1; > - return (int)(i % obj_allocs); > + int cnt; > + unsigned int ix = *sha1++; > + > + for (cnt = 1; cnt < sizeof(unsigned int); cnt++) { > + ix <<= 8; > + ix |= *sha1++; > + } memcpy(&ix, sha1, sizeof(ix)); (GCC should do the rest.) > + return (int)(ix % obj_allocs); > } return (int)(ix & (obj_allocs - 1)); AFAICS, obj_allocs is a power of two.