summaryrefslogtreecommitdiffstats
path: root/src/libutil/uthash_strcase.h
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@highsecure.ru>2016-06-10 14:46:03 +0100
committerVsevolod Stakhov <vsevolod@highsecure.ru>2016-06-10 14:46:03 +0100
commit1b39a1b22f04395501138a8b31196704dbc21e59 (patch)
treec62b76203ae19810f461f4f60a2ef9f4468ae5fe /src/libutil/uthash_strcase.h
parent42acc1f6bb3e8f4ba967bbedc73ab7e6f043518b (diff)
downloadrspamd-1b39a1b22f04395501138a8b31196704dbc21e59.tar.gz
rspamd-1b39a1b22f04395501138a8b31196704dbc21e59.zip
[Fix] Improve strcase hash used in uthash
Diffstat (limited to 'src/libutil/uthash_strcase.h')
-rw-r--r--src/libutil/uthash_strcase.h62
1 files changed, 49 insertions, 13 deletions
diff --git a/src/libutil/uthash_strcase.h b/src/libutil/uthash_strcase.h
index 5d1df130f..45ed84f67 100644
--- a/src/libutil/uthash_strcase.h
+++ b/src/libutil/uthash_strcase.h
@@ -16,30 +16,66 @@
#ifndef UTHASH_STRCASE_H_
#define UTHASH_STRCASE_H_
-#include "xxhash.h"
-
/* Utils for uthash tuning */
#ifndef HASH_CASELESS
#define HASH_FUNCTION(key,keylen,num_bkts,hashv,bkt) do {\
- hashv = XXH32(key, keylen, 0); \
+ hashv = mum(key, keylen, 0xdeadbabe); \
bkt = (hashv) & (num_bkts-1); \
} while (0)
#define HASH_KEYCMP(a,b,len) memcmp(a,b,len)
#else
#define HASH_FUNCTION(key,keylen,num_bkts,hashv,bkt) do {\
- XXH32_state_t xxh; \
- XXH32_reset(&xxh, 0xdead); \
- unsigned char *p = (unsigned char *)key, t; \
- for (unsigned int i = 0; i < keylen; i ++) { \
- t = g_ascii_tolower(p[i]); \
- XXH32_update(&xxh, &t, 1); \
- } \
- hashv = XXH32_digest(&xxh); \
- bkt = (hashv) & (num_bkts-1); \
+ unsigned len = keylen; \
+ unsigned leftover = keylen % 8; \
+ unsigned fp, i; \
+ const uint8_t* s = (const uint8_t*)key; \
+ union { \
+ struct { \
+ unsigned char c1, c2, c3, c4, c5, c6, c7, c8; \
+ } c; \
+ uint64_t pp; \
+ } u; \
+ uint64_t r; \
+ fp = len - leftover; \
+ r = 0xdeadbabe; \
+ for (i = 0; i != fp; i += 8) { \
+ u.c.c1 = s[i], u.c.c2 = s[i + 1], u.c.c3 = s[i + 2], u.c.c4 = s[i + 3]; \
+ u.c.c5 = s[i + 4], u.c.c6 = s[i + 5], u.c.c7 = s[i + 6], u.c.c8 = s[i + 7]; \
+ u.c.c1 = lc_map[u.c.c1]; \
+ u.c.c2 = lc_map[u.c.c2]; \
+ u.c.c3 = lc_map[u.c.c3]; \
+ u.c.c4 = lc_map[u.c.c4]; \
+ u.c.c1 = lc_map[u.c.c5]; \
+ u.c.c2 = lc_map[u.c.c6]; \
+ u.c.c3 = lc_map[u.c.c7]; \
+ u.c.c4 = lc_map[u.c.c8]; \
+ r = mum_hash_step (r, u.pp); \
+ } \
+ u.pp = 0; \
+ switch (leftover) { \
+ case 7: \
+ u.c.c7 = lc_map[(unsigned char)s[i++]]; \
+ case 6: \
+ u.c.c6 = lc_map[(unsigned char)s[i++]]; \
+ case 5: \
+ u.c.c5 = lc_map[(unsigned char)s[i++]]; \
+ case 4: \
+ u.c.c4 = lc_map[(unsigned char)s[i++]]; \
+ case 3: \
+ u.c.c3 = lc_map[(unsigned char)s[i++]]; \
+ case 2: \
+ u.c.c2 = lc_map[(unsigned char)s[i++]]; \
+ case 1: \
+ u.c.c1 = lc_map[(unsigned char)s[i]]; \
+ r = mum_hash_step (r, u.pp); \
+ break; \
+ } \
+ hashv = mum_hash_finish (r); \
+ bkt = (hashv) & (num_bkts-1); \
} while (0)
-#define HASH_KEYCMP(a,b,len) strncasecmp(a,b,len)
+#define HASH_KEYCMP(a,b,len) rspamd_lc_cmp(a,b,len)
#endif
#include "uthash.h"