Re: I'm a total push-over..
On Thu, Jan 24, 2008 at 09:15:43AM -0800, Linus Torvalds wrote:
>
>
> You can do a perfectly fine 8-bytes-at-a-time hash for almost 100% of all
I suppose 8 bytes for 64-bit platforms and 4 bytes for 32-bits.
Show 25 quoted lines
>
> unsigned int name_hash(const char *name, int size)
> {
> hash = HASH_INIT;
> do {
> unsigned char c;
> if (size >= sizeof(long)) {
> unsigned long val = get_unaligned_long(name);
> if (!(val & 0x8080808080808080)) {
> /* Make it equivalent in case */
> val &= ~0x2020202020202020;
> hash = hash_long(hash, val);
> name += sizeof(long);
> size -= sizeof(long);
> continue;
> }
> }
>
> c = *name;
> if (!(c & 0x80)) {
> hash = hash_long(hash, c & ~0x20);
> name++;
> size--;
> continue;
> }It is better to use 'while' instead of 'if' here, i.e.:
while (!((c = *name) & 0x80)) {
hash = hash_long(hash, c & ~0x20);
name++;
if (!--size)
return hash;
}Show 6 quoted lines
>
> /* This is the unusual and slowish case */
> hash = hash_utf8_char(hash, c, &name, &size);
> } while (size);
> return hassh;
> }