]> source.dussan.org Git - rspamd.git/commitdiff
Use regexp hash functions for task re_cache.
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Thu, 19 Mar 2015 18:43:03 +0000 (18:43 +0000)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Thu, 19 Mar 2015 18:43:03 +0000 (18:43 +0000)
src/libserver/task.c
src/libutil/regexp.c
src/libutil/regexp.h

index f6eeef2b1796c3115e28d2660303974e9d65fccc..a4286634ff9845a5d9d98aa60e0eb51a92d82609 100644 (file)
@@ -73,7 +73,7 @@ rspamd_task_new (struct rspamd_worker *worker)
        rspamd_mempool_add_destructor (new_task->task_pool,
                (rspamd_mempool_destruct_t) g_hash_table_unref,
                new_task->results);
-       new_task->re_cache = g_hash_table_new (rspamd_str_hash, rspamd_str_equal);
+       new_task->re_cache = g_hash_table_new (rspamd_regexp_hash, rspamd_regexp_equal);
        rspamd_mempool_add_destructor (new_task->task_pool,
                (rspamd_mempool_destruct_t) g_hash_table_unref,
                new_task->re_cache);
index b8bd4454cb72fc4e9a51657783aefd4cc9555aa9..bf1a1762d2b7521f20dfa34a66303056db458792 100644 (file)
@@ -436,7 +436,7 @@ rspamd_regexp_get_ud (rspamd_regexp_t *re)
        return re->ud;
 }
 
-static gboolean
+gboolean
 rspamd_regexp_equal (gconstpointer a, gconstpointer b)
 {
        const guchar *ia = a, *ib = b;
@@ -444,7 +444,7 @@ rspamd_regexp_equal (gconstpointer a, gconstpointer b)
        return (memcmp (ia, ib, sizeof (regexp_id_t)) == 0);
 }
 
-static guint32
+guint32
 rspamd_regexp_hash (gconstpointer a)
 {
        const guchar *ia = a;
index 3c08de71a88fb21a2f125ff651627271cb7f85b7..fc236c1b3dcfeffc979b2b917dff6b8cd370d515 100644 (file)
@@ -89,6 +89,13 @@ void rspamd_regexp_set_ud (rspamd_regexp_t *re, gpointer ud);
  */
 gpointer rspamd_regexp_get_ud (rspamd_regexp_t *re);
 
+/**
+ * Get regexp ID suitable for hashing
+ * @param re
+ * @return
+ */
+gpointer rspamd_regexp_get_id (rspamd_regexp_t *re);
+
 /**
  * Get pattern for the specified regexp object
  * @param re
@@ -151,6 +158,21 @@ gboolean rspamd_regexp_cache_remove (struct rspamd_regexp_cache *cache,
  */
 void rspamd_regexp_cache_destroy (struct rspamd_regexp_cache *cache);
 
+/**
+ * Return the value for regexp hash based on its ID
+ * @param a
+ * @return
+ */
+guint32 rspamd_regexp_hash (gconstpointer a);
+
+/**
+ * Compare two regexp objects based on theirs ID
+ * @param a
+ * @param b
+ * @return
+ */
+gboolean rspamd_regexp_equal (gconstpointer a, gconstpointer b);
+
 /**
  * Initialize superglobal regexp cache and library
  */