/* Process cache item */
if (task->cfg->cache) {
- cur = task->cfg->cache->static_items;
- while (cur)
- {
- item = cur->data;
-
- if (strcmp (item->s->symbol, symbol) == 0) {
- item->s->frequency++;
- }
- cur = g_list_next (cur);
- }
- cur = task->cfg->cache->negative_items;
- while (cur)
- {
- item = cur->data;
-
- if (strcmp (item->s->symbol, symbol) == 0) {
- item->s->frequency++;
- }
- cur = g_list_next (cur);
+ item = g_hash_table_lookup (task->cfg->cache->items_by_symbol, symbol);
+ if (item != NULL) {
+ item->s->frequency++;
}
}
{
guint8 *tmp;
struct _pool_chain *new, *cur;
+ gsize free;
if (pool) {
#ifdef MEMORY_GREEDY
cur = pool->cur_pool;
#endif
/* Find free space in pool chain */
- while (pool_chain_free (cur) < size && cur->next) {
+ while ((free = pool_chain_free (cur)) < size && cur->next) {
cur = cur->next;
}
- if (cur->next == NULL) {
+ if (free < size && cur->next == NULL) {
/* Allocate new pool */
if (cur->len >= size) {
new = pool_chain_new (cur->len);
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);
}
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);
}
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);
}
/* 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;
}