Re: I'm a total push-over..
From: Dmitry Potapov <hidden>
Date: 2016-06-15 22:44:08
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.
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;
}
/* This is the unusual and slowish case */ hash = hash_utf8_char(hash, c, &name, &size); } while (size); return hassh; }
Dmitry