mirror of
https://codeberg.org/redict/redict.git
synced 2025-01-23 08:38:27 -05:00
Use locale agnostic tolower() in dict.c hash function.
This commit is contained in:
parent
05ea8c6122
commit
84fa8230e5
@ -204,7 +204,7 @@ $(REDIS_CHECK_AOF_NAME): $(REDIS_CHECK_AOF_OBJ)
|
|||||||
$(REDIS_LD) -o $@ $^ $(FINAL_LIBS)
|
$(REDIS_LD) -o $@ $^ $(FINAL_LIBS)
|
||||||
|
|
||||||
dict-benchmark: dict.c zmalloc.c sds.c
|
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,
|
# 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
|
# building it should complete before building any other object. Instead of
|
||||||
|
@ -1109,7 +1109,7 @@ void dictGetStats(char *buf, size_t bufsize, dict *d) {
|
|||||||
|
|
||||||
#include "sds.h"
|
#include "sds.h"
|
||||||
|
|
||||||
unsigned int hashCallback(const void *key) {
|
uint64_t hashCallback(const void *key) {
|
||||||
return dictGenHashFunction((unsigned char*)key, sdslen((char*)key));
|
return dictGenHashFunction((unsigned char*)key, sdslen((char*)key));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -40,6 +40,16 @@
|
|||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
|
|
||||||
|
/* 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.
|
/* Test of the CPU is Little Endian and supports not aligned accesses.
|
||||||
* Two interesting conditions to speedup the function that happen to be
|
* Two interesting conditions to speedup the function that happen to be
|
||||||
* in most of x86 servers. */
|
* in most of x86 servers. */
|
||||||
@ -70,14 +80,14 @@
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define U8TO64_LE_NOCASE(p) \
|
#define U8TO64_LE_NOCASE(p) \
|
||||||
(((uint64_t)(tolower((p)[0]))) | \
|
(((uint64_t)(siptlw((p)[0]))) | \
|
||||||
((uint64_t)(tolower((p)[1])) << 8) | \
|
((uint64_t)(siptlw((p)[1])) << 8) | \
|
||||||
((uint64_t)(tolower((p)[2])) << 16) | \
|
((uint64_t)(siptlw((p)[2])) << 16) | \
|
||||||
((uint64_t)(tolower((p)[3])) << 24) | \
|
((uint64_t)(siptlw((p)[3])) << 24) | \
|
||||||
((uint64_t)(tolower((p)[4])) << 32) | \
|
((uint64_t)(siptlw((p)[4])) << 32) | \
|
||||||
((uint64_t)(tolower((p)[5])) << 40) | \
|
((uint64_t)(siptlw((p)[5])) << 40) | \
|
||||||
((uint64_t)(tolower((p)[6])) << 48) | \
|
((uint64_t)(siptlw((p)[6])) << 48) | \
|
||||||
((uint64_t)(tolower((p)[7])) << 56))
|
((uint64_t)(siptlw((p)[7])) << 56))
|
||||||
|
|
||||||
#define SIPROUND \
|
#define SIPROUND \
|
||||||
do { \
|
do { \
|
||||||
@ -192,13 +202,13 @@ uint64_t siphash_nocase(const uint8_t *in, const size_t inlen, const uint8_t *k)
|
|||||||
}
|
}
|
||||||
|
|
||||||
switch (left) {
|
switch (left) {
|
||||||
case 7: b |= ((uint64_t)tolower(in[6])) << 48;
|
case 7: b |= ((uint64_t)siptlw(in[6])) << 48;
|
||||||
case 6: b |= ((uint64_t)tolower(in[5])) << 40;
|
case 6: b |= ((uint64_t)siptlw(in[5])) << 40;
|
||||||
case 5: b |= ((uint64_t)tolower(in[4])) << 32;
|
case 5: b |= ((uint64_t)siptlw(in[4])) << 32;
|
||||||
case 4: b |= ((uint64_t)tolower(in[3])) << 24;
|
case 4: b |= ((uint64_t)siptlw(in[3])) << 24;
|
||||||
case 3: b |= ((uint64_t)tolower(in[2])) << 16;
|
case 3: b |= ((uint64_t)siptlw(in[2])) << 16;
|
||||||
case 2: b |= ((uint64_t)tolower(in[1])) << 8;
|
case 2: b |= ((uint64_t)siptlw(in[1])) << 8;
|
||||||
case 1: b |= ((uint64_t)tolower(in[0])); break;
|
case 1: b |= ((uint64_t)siptlw(in[0])); break;
|
||||||
case 0: break;
|
case 0: break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user