diff options
author | Vsevolod Stakhov <vsevolod@rspamd.com> | 2023-07-26 10:49:23 +0100 |
---|---|---|
committer | Vsevolod Stakhov <vsevolod@rspamd.com> | 2023-07-26 10:49:23 +0100 |
commit | 537a7180a0d5132c11636c4fd8b1450cd99d352c (patch) | |
tree | fb9f8c84955a411bdffbd6371ea32f2716fb3687 /src/libutil/uthash_strcase.h | |
parent | 5fd7a90fdaa33f52c59bdb0ca84451e5c1e22365 (diff) | |
download | rspamd-537a7180a0d5132c11636c4fd8b1450cd99d352c.tar.gz rspamd-537a7180a0d5132c11636c4fd8b1450cd99d352c.zip |
[Rework] Use clang-format to unify formatting in all sources
No meaningful changes.
Diffstat (limited to 'src/libutil/uthash_strcase.h')
-rw-r--r-- | src/libutil/uthash_strcase.h | 112 |
1 files changed, 57 insertions, 55 deletions
diff --git a/src/libutil/uthash_strcase.h b/src/libutil/uthash_strcase.h index a4418b442..86075ee68 100644 --- a/src/libutil/uthash_strcase.h +++ b/src/libutil/uthash_strcase.h @@ -25,63 +25,65 @@ /* Utils for uthash tuning */ #ifndef HASH_CASELESS -#define HASH_FUNCTION(key,keylen,num_bkts,hashv,bkt) do {\ - hashv = (__typeof (hashv))rspamd_cryptobox_fast_hash(key, keylen, rspamd_hash_seed ()); \ - bkt = (hashv) & (num_bkts-1); \ -} while (0) +#define HASH_FUNCTION(key, keylen, num_bkts, hashv, bkt) \ + do { \ + hashv = (__typeof(hashv)) rspamd_cryptobox_fast_hash(key, keylen, rspamd_hash_seed()); \ + bkt = (hashv) & (num_bkts - 1); \ + } while (0) -#define HASH_KEYCMP(a,b,len) memcmp(a,b,len) +#define HASH_KEYCMP(a, b, len) memcmp(a, b, len) #else -#define HASH_FUNCTION(key,keylen,num_bkts,hashv,bkt) do {\ - unsigned _len = keylen; \ - rspamd_cryptobox_fast_hash_state_t _hst; \ - 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; \ - _fp = _len - _leftover; \ - rspamd_cryptobox_fast_hash_init (&_hst, rspamd_hash_seed ()); \ - 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]; \ - rspamd_cryptobox_fast_hash_update (&_hst, &_u, sizeof (_u)); \ - } \ - _u.pp = 0; \ - switch (_leftover) { \ - case 7: \ - /* fallthrough */ _u.c.c7 = lc_map[(unsigned char)_s[_i++]]; \ - case 6: \ - /* fallthrough */ _u.c.c6 = lc_map[(unsigned char)_s[_i++]]; \ - case 5: \ - /* fallthrough */ _u.c.c5 = lc_map[(unsigned char)_s[_i++]]; \ - case 4: \ - /* fallthrough */ _u.c.c4 = lc_map[(unsigned char)_s[_i++]]; \ - case 3: \ - /* fallthrough */ _u.c.c3 = lc_map[(unsigned char)_s[_i++]]; \ - case 2: \ - /* fallthrough */ _u.c.c2 = lc_map[(unsigned char)_s[_i++]]; \ - case 1: \ - /* fallthrough */ _u.c.c1 = lc_map[(unsigned char)_s[_i]]; \ - rspamd_cryptobox_fast_hash_update (&_hst, &_u, sizeof (_u)); \ - break; \ - } \ - hashv = (__typeof (hashv))rspamd_cryptobox_fast_hash_final (&_hst); \ - bkt = (hashv) & (num_bkts-1); \ -} while (0) -#define HASH_KEYCMP(a,b,len) rspamd_lc_cmp(a,b,len) +#define HASH_FUNCTION(key, keylen, num_bkts, hashv, bkt) \ + do { \ + unsigned _len = keylen; \ + rspamd_cryptobox_fast_hash_state_t _hst; \ + 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; \ + _fp = _len - _leftover; \ + rspamd_cryptobox_fast_hash_init(&_hst, rspamd_hash_seed()); \ + 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]; \ + rspamd_cryptobox_fast_hash_update(&_hst, &_u, sizeof(_u)); \ + } \ + _u.pp = 0; \ + switch (_leftover) { \ + case 7: \ + /* fallthrough */ _u.c.c7 = lc_map[(unsigned char) _s[_i++]]; \ + case 6: \ + /* fallthrough */ _u.c.c6 = lc_map[(unsigned char) _s[_i++]]; \ + case 5: \ + /* fallthrough */ _u.c.c5 = lc_map[(unsigned char) _s[_i++]]; \ + case 4: \ + /* fallthrough */ _u.c.c4 = lc_map[(unsigned char) _s[_i++]]; \ + case 3: \ + /* fallthrough */ _u.c.c3 = lc_map[(unsigned char) _s[_i++]]; \ + case 2: \ + /* fallthrough */ _u.c.c2 = lc_map[(unsigned char) _s[_i++]]; \ + case 1: \ + /* fallthrough */ _u.c.c1 = lc_map[(unsigned char) _s[_i]]; \ + rspamd_cryptobox_fast_hash_update(&_hst, &_u, sizeof(_u)); \ + break; \ + } \ + hashv = (__typeof(hashv)) rspamd_cryptobox_fast_hash_final(&_hst); \ + bkt = (hashv) & (num_bkts - 1); \ + } while (0) +#define HASH_KEYCMP(a, b, len) rspamd_lc_cmp(a, b, len) #endif #include "uthash.h" |