summaryrefslogtreecommitdiffstats
path: root/src/symbols_cache.c
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@rambler-co.ru>2011-07-26 15:32:44 +0400
committerVsevolod Stakhov <vsevolod@rambler-co.ru>2011-07-26 15:32:44 +0400
commit33f9a2a6f1c799f3f51c065485dfa1761053e88b (patch)
treecc9d5f5b3a17ab68424024a6fcfb77aa008dd0bd /src/symbols_cache.c
parentdd14cd445a856de79541512ed27a1161a159afac (diff)
downloadrspamd-33f9a2a6f1c799f3f51c065485dfa1761053e88b.tar.gz
rspamd-33f9a2a6f1c799f3f51c065485dfa1761053e88b.zip
Fix very bad bug in a memory pool allocator.
Speed up inserting symbols by hashing them.
Diffstat (limited to 'src/symbols_cache.c')
-rw-r--r--src/symbols_cache.c9
1 files changed, 8 insertions, 1 deletions
diff --git a/src/symbols_cache.c b/src/symbols_cache.c
index c4327b470..3684bd5e5 100644
--- a/src/symbols_cache.c
+++ b/src/symbols_cache.c
@@ -120,12 +120,14 @@ post_cache_init (struct symbols_cache *cache)
while (cur) {
item = cur->data;
total_frequency += item->s->frequency;
+ g_hash_table_insert (cache->items_by_symbol, item->s->symbol, item);
cur = g_list_next (cur);
}
cur = g_list_first (cache->static_items);
while (cur) {
item = cur->data;
total_frequency += item->s->frequency;
+ g_hash_table_insert (cache->items_by_symbol, item->s->symbol, item);
cur = g_list_next (cur);
}
@@ -388,6 +390,8 @@ register_dynamic_symbol (memory_pool_t *dynamic_pool, struct symbols_cache **cac
msg_debug ("used items: %d, added symbol: %s", (*cache)->used_items, name);
set_counter (item->s->symbol, 0);
+ g_hash_table_insert (pcache->items_by_symbol, item->s->symbol, item);
+
if (networks == NULL) {
pcache->dynamic_items = g_list_prepend (pcache->dynamic_items, item);
}
@@ -497,7 +501,7 @@ free_cache (gpointer arg)
if (cache->negative_dynamic_map) {
radix_tree_free (cache->negative_dynamic_map);
}
-
+ g_hash_table_destroy (cache->items_by_symbol);
memory_pool_delete (cache->static_pool);
g_free (cache);
@@ -618,7 +622,10 @@ init_symbols_cache (memory_pool_t * pool, struct symbols_cache *cache, struct co
}
/* MMap cache file and copy saved_cache structures */
res = mmap_cache_file (cache, fd, pool);
+ cache->items_by_symbol = g_hash_table_new (g_str_hash, g_str_equal);
+
memory_pool_add_destructor (pool, (pool_destruct_func)free_cache, cache);
+
return res;
}