Re: [PATCH] Use a hashtable for objects instead of a sorted list
Show 5 quoted lines
> static int hashtable_index(const unsigned char *sha1)
> {
> - unsigned int i = *(unsigned int *)sha1;
> - return (int)(i % obj_allocs);
> + int cnt;Show 6 quoted lines
> + 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.