Re: I'm a total push-over..

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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
-
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]

  Powered by Linux