X-Git-Url: https://git.ozlabs.org/?p=ccan;a=blobdiff_plain;f=ccan%2Fhash%2Fhash.c;h=5ccc695505e76929cffccc7a4f5dbbde44e7f72d;hp=a9948821227899190dae5e79c63cb435e7d5d575;hb=6585f22b6d9e1b00eeaea2d4539a098d5fc2681c;hpb=0a36c4014ffa3fc35d70f69303b6a9d3c697c693 diff --git a/ccan/hash/hash.c b/ccan/hash/hash.c index a9948821..5ccc6955 100644 --- a/ccan/hash/hash.c +++ b/ccan/hash/hash.c @@ -1,3 +1,4 @@ +/* CC0 (Public domain) - see LICENSE file for details */ /* ------------------------------------------------------------------------------- lookup3.c, by Bob Jenkins, May 2006, Public Domain. @@ -40,9 +41,7 @@ on 1 byte), but shoehorning those bytes into integers efficiently is messy. #include /* defines time_t for timings in the test */ #include /* defines uint32_t etc */ #include /* attempt to define endianness */ -#endif -#include "hash.h" #ifdef linux # include /* attempt to define endianness */ #endif @@ -66,6 +65,19 @@ on 1 byte), but shoehorning those bytes into integers efficiently is messy. #else # error Unknown endian #endif +#endif /* old hash.c headers. */ + +#include "hash.h" + +#if HAVE_LITTLE_ENDIAN +#define HASH_LITTLE_ENDIAN 1 +#define HASH_BIG_ENDIAN 0 +#elif HAVE_BIG_ENDIAN +#define HASH_LITTLE_ENDIAN 0 +#define HASH_BIG_ENDIAN 1 +#else +#error Unknown endian +#endif #define hashsize(n) ((uint32_t)1<<(n)) #define hashmask(n) (hashsize(n)-1) @@ -248,9 +260,7 @@ static uint32_t hashlittle( const void *key, size_t length, uint32_t *val2 ) u.ptr = key; if (HASH_LITTLE_ENDIAN && ((u.i & 0x3) == 0)) { const uint32_t *k = (const uint32_t *)key; /* read 32-bit chunks */ -#ifdef VALGRIND const uint8_t *k8; -#endif /*------ all but last block: aligned reads and affect 32 bits of (a,b,c) */ while (length > 12) @@ -272,9 +282,10 @@ static uint32_t hashlittle( const void *key, size_t length, uint32_t *val2 ) * does it on word boundaries, so is OK with this. But VALGRIND will * still catch it and complain. The masking trick does make the hash * noticably faster for short strings (like English words). + * + * Not on my testing with gcc 4.5 on an intel i5 CPU, at least --RR. */ -#ifndef VALGRIND - +#if 0 switch(length) { case 12: c+=k[2]; b+=k[1]; a+=k[0]; break; @@ -426,9 +437,7 @@ static uint32_t hashbig( const void *key, size_t length, uint32_t *val2) u.ptr = key; if (HASH_BIG_ENDIAN && ((u.i & 0x3) == 0)) { const uint32_t *k = (const uint32_t *)key; /* read 32-bit chunks */ -#ifdef VALGRIND const uint8_t *k8; -#endif /*------ all but last block: aligned reads and affect 32 bits of (a,b,c) */ while (length > 12) @@ -450,9 +459,10 @@ static uint32_t hashbig( const void *key, size_t length, uint32_t *val2) * does it on word boundaries, so is OK with this. But VALGRIND will * still catch it and complain. The masking trick does make the hash * noticably faster for short strings (like English words). + * + * Not on my testing with gcc 4.5 on an intel i5 CPU, at least --RR. */ -#ifndef VALGRIND - +#if 0 switch(length) { case 12: c+=k[2]; b+=k[1]; a+=k[0]; break;