From c477b4b5252adb3150ec7dfb761383e3e619453c Mon Sep 17 00:00:00 2001 From: Vsevolod Stakhov Date: Sat, 17 Jun 2023 15:01:36 +0100 Subject: [Minor] Define simple ftok hash and equal functions --- src/libutil/str_util.c | 21 --------------------- src/libutil/str_util.h | 6 +++--- 2 files changed, 3 insertions(+), 24 deletions(-) (limited to 'src') diff --git a/src/libutil/str_util.c b/src/libutil/str_util.c index 86369909a..dc45cba45 100644 --- a/src/libutil/str_util.c +++ b/src/libutil/str_util.c @@ -332,27 +332,6 @@ rspamd_ftok_icase_hash (gconstpointer key) return (guint)rspamd_icase_hash (f->begin, f->len, rspamd_hash_seed ()); } -gboolean -rspamd_ftok_equal (gconstpointer v, gconstpointer v2) -{ - const rspamd_ftok_t *f1 = v, *f2 = v2; - - if (f1->len == f2->len && - memcmp (f1->begin, f2->begin, f1->len) == 0) { - return TRUE; - } - - return FALSE; -} - -guint -rspamd_ftok_hash (gconstpointer key) -{ - const rspamd_ftok_t *f = key; - - return (guint)rspamd_cryptobox_fast_hash (f->begin, f->len, rspamd_hash_seed ()); -} - gboolean rspamd_gstring_icase_equal (gconstpointer v, gconstpointer v2) { diff --git a/src/libutil/str_util.h b/src/libutil/str_util.h index 199a384ca..c0b9c1323 100644 --- a/src/libutil/str_util.h +++ b/src/libutil/str_util.h @@ -80,9 +80,9 @@ guint rspamd_ftok_icase_hash (gconstpointer key); gboolean rspamd_ftok_icase_equal (gconstpointer v, gconstpointer v2); -guint rspamd_ftok_hash (gconstpointer key); - -gboolean rspamd_ftok_equal (gconstpointer v, gconstpointer v2); +/* Use in khash for speed */ +#define rspamd_ftok_hash(key) _wyhash32((key)->begin, (key)->len, 0) +#define rspamd_ftok_equal(v1, v2) ((v1)->len == (v2)->len && memcmp((v1)->begin, (v2)->begin, (v1)->len) == 0) guint rspamd_gstring_icase_hash (gconstpointer key); -- cgit v1.2.3