diff --git a/src/Makefile b/src/Makefile index 5f7536e8..cb7afa02 100644 --- a/src/Makefile +++ b/src/Makefile @@ -204,7 +204,7 @@ $(REDIS_CHECK_AOF_NAME): $(REDIS_CHECK_AOF_OBJ) $(REDIS_LD) -o $@ $^ $(FINAL_LIBS) dict-benchmark: dict.c zmalloc.c sds.c - $(REDIS_CC) $(FINAL_CFLAGS) dict.c zmalloc.c sds.c -D DICT_BENCHMARK_MAIN -o dict-benchmark + $(REDIS_CC) $(FINAL_CFLAGS) dict.c zmalloc.c sds.c siphash.c -D DICT_BENCHMARK_MAIN -o dict-benchmark # Because the jemalloc.h header is generated as a part of the jemalloc build, # building it should complete before building any other object. Instead of diff --git a/src/dict.c b/src/dict.c index 8ce73596..69fb3b8f 100644 --- a/src/dict.c +++ b/src/dict.c @@ -1109,7 +1109,7 @@ void dictGetStats(char *buf, size_t bufsize, dict *d) { #include "sds.h" -unsigned int hashCallback(const void *key) { +uint64_t hashCallback(const void *key) { return dictGenHashFunction((unsigned char*)key, sdslen((char*)key)); } diff --git a/src/siphash.c b/src/siphash.c index 3bcada72..7219d4b8 100644 --- a/src/siphash.c +++ b/src/siphash.c @@ -40,6 +40,16 @@ #include #include +/* Fast tolower() alike function that does not care about locale + * but just returns a-z insetad of A-Z. */ +int siptlw(int c) { + if (c >= 'A' && c <= 'Z') { + return c+('a'-'A'); + } else { + return c; + } +} + /* Test of the CPU is Little Endian and supports not aligned accesses. * Two interesting conditions to speedup the function that happen to be * in most of x86 servers. */ @@ -70,14 +80,14 @@ #endif #define U8TO64_LE_NOCASE(p) \ - (((uint64_t)(tolower((p)[0]))) | \ - ((uint64_t)(tolower((p)[1])) << 8) | \ - ((uint64_t)(tolower((p)[2])) << 16) | \ - ((uint64_t)(tolower((p)[3])) << 24) | \ - ((uint64_t)(tolower((p)[4])) << 32) | \ - ((uint64_t)(tolower((p)[5])) << 40) | \ - ((uint64_t)(tolower((p)[6])) << 48) | \ - ((uint64_t)(tolower((p)[7])) << 56)) + (((uint64_t)(siptlw((p)[0]))) | \ + ((uint64_t)(siptlw((p)[1])) << 8) | \ + ((uint64_t)(siptlw((p)[2])) << 16) | \ + ((uint64_t)(siptlw((p)[3])) << 24) | \ + ((uint64_t)(siptlw((p)[4])) << 32) | \ + ((uint64_t)(siptlw((p)[5])) << 40) | \ + ((uint64_t)(siptlw((p)[6])) << 48) | \ + ((uint64_t)(siptlw((p)[7])) << 56)) #define SIPROUND \ do { \ @@ -192,13 +202,13 @@ uint64_t siphash_nocase(const uint8_t *in, const size_t inlen, const uint8_t *k) } switch (left) { - case 7: b |= ((uint64_t)tolower(in[6])) << 48; - case 6: b |= ((uint64_t)tolower(in[5])) << 40; - case 5: b |= ((uint64_t)tolower(in[4])) << 32; - case 4: b |= ((uint64_t)tolower(in[3])) << 24; - case 3: b |= ((uint64_t)tolower(in[2])) << 16; - case 2: b |= ((uint64_t)tolower(in[1])) << 8; - case 1: b |= ((uint64_t)tolower(in[0])); break; + case 7: b |= ((uint64_t)siptlw(in[6])) << 48; + case 6: b |= ((uint64_t)siptlw(in[5])) << 40; + case 5: b |= ((uint64_t)siptlw(in[4])) << 32; + case 4: b |= ((uint64_t)siptlw(in[3])) << 24; + case 3: b |= ((uint64_t)siptlw(in[2])) << 16; + case 2: b |= ((uint64_t)siptlw(in[1])) << 8; + case 1: b |= ((uint64_t)siptlw(in[0])); break; case 0: break; }