From: Vsevolod Stakhov Date: Sat, 7 Mar 2015 22:46:13 +0000 (+0000) Subject: Fix cache usage for rspamd_regexp. X-Git-Tag: 0.9.0~535 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=ed492b2b9f25474c7faa3fffbc9abe0328733278;p=rspamd.git Fix cache usage for rspamd_regexp. --- diff --git a/src/libmime/expressions.c b/src/libmime/expressions.c index aab78df5c..547cc0d58 100644 --- a/src/libmime/expressions.c +++ b/src/libmime/expressions.c @@ -653,6 +653,7 @@ parse_regexp (rspamd_mempool_t * pool, const gchar *line, gboolean raw_mode) const gchar *begin, *end, *p, *src, *start; gchar *dbegin, *dend; struct rspamd_regexp_element *result; + rspamd_regexp_t *re; GError *err = NULL; GString *re_flags; @@ -661,6 +662,10 @@ parse_regexp (rspamd_mempool_t * pool, const gchar *line, gboolean raw_mode) return NULL; } + if ((re = rspamd_regexp_cache_query (NULL, line, NULL)) != NULL) { + return ((struct rspamd_regexp_element *)rspamd_regexp_get_ud (re)); + } + src = line; result = rspamd_mempool_alloc0 (pool, sizeof (struct rspamd_regexp_element)); /* Skip whitespaces */ @@ -798,7 +803,7 @@ parse_regexp (rspamd_mempool_t * pool, const gchar *line, gboolean raw_mode) g_string_append_c (re_flags, 'r'); } - result->regexp = rspamd_regexp_cache_create (NULL, dbegin, re_flags->str, + result->regexp = rspamd_regexp_new (dbegin, re_flags->str, &err); g_string_free (re_flags, TRUE); @@ -814,6 +819,10 @@ parse_regexp (rspamd_mempool_t * pool, const gchar *line, gboolean raw_mode) (rspamd_mempool_destruct_t) rspamd_regexp_unref, (void *)result->regexp); + rspamd_regexp_set_ud (result->regexp, result); + + rspamd_regexp_cache_insert (NULL, line, NULL, result->regexp); + *dend = '/'; return result;