From: Vsevolod Stakhov Date: Thu, 19 Mar 2015 18:57:43 +0000 (+0000) Subject: Add re cache logic to task routines. X-Git-Tag: 0.9.0~451^2~14 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=759edd03e2d11c2f44ccc91b0160e05d22e4f29b;p=rspamd.git Add re cache logic to task routines. --- diff --git a/src/libserver/task.c b/src/libserver/task.c index a4286634f..8f5334927 100644 --- a/src/libserver/task.c +++ b/src/libserver/task.c @@ -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_regexp_hash, rspamd_regexp_equal); + new_task->re_cache = g_hash_table_new (rspamd_str_hash, rspamd_str_equal); rspamd_mempool_add_destructor (new_task->task_pool, (rspamd_mempool_destruct_t) g_hash_table_unref, new_task->re_cache); @@ -450,3 +450,37 @@ rspamd_task_add_sender (struct rspamd_task *task, const gchar *sender) return FALSE; } + + +guint +rspamd_task_re_cache_add (struct rspamd_task *task, gchar *re, + guint value) +{ + guint ret = RSPAMD_TASK_CACHE_NO_VALUE; + gpointer p; + + p = g_hash_table_lookup (task->re_cache, re); + + if (p != NULL) { + ret = GPOINTER_TO_INT (p); + } + + g_hash_table_insert (task->re_cache, re, GINT_TO_POINTER (value)); + + return ret; +} + +guint +rspamd_task_re_cache_check (struct rspamd_task *task, const gchar *re) +{ + guint ret = RSPAMD_TASK_CACHE_NO_VALUE; + gpointer p; + + p = g_hash_table_lookup (task->re_cache, re); + + if (p != NULL) { + ret = GPOINTER_TO_INT (p); + } + + return ret; +} diff --git a/src/libserver/task.h b/src/libserver/task.h index 799182f01..f4f22823f 100644 --- a/src/libserver/task.h +++ b/src/libserver/task.h @@ -218,5 +218,24 @@ gboolean rspamd_task_add_recipient (struct rspamd_task *task, const gchar *rcpt) */ gboolean rspamd_task_add_sender (struct rspamd_task *task, const gchar *sender); +#define RSPAMD_TASK_CACHE_NO_VALUE ((guint)-1) + +/** + * Add or replace the value to the task cache of regular expressions results + * @param task task object + * @param re text value of regexp + * @param value value to add + * @return previous value of element or RSPAMD_TASK_CACHE_NO_VALUE + */ +guint rspamd_task_re_cache_add (struct rspamd_task *task, gchar *re, + guint value); + +/** + * Check for cached result of re inside cache + * @param task task object + * @param re text value of regexp + * @return the current value of element or RSPAMD_TASK_CACHE_NO_VALUE + */ +guint rspamd_task_re_cache_check (struct rspamd_task *task, const gchar *re); #endif /* TASK_H_ */