if (item != NULL) {
if (item->is_virtual) {
- item = g_ptr_array_index (cache->filters,
+ item = g_ptr_array_index (cache->items_by_id,
item->specific.virtual.parent);
}
cur = g_list_next (cur);
}
- for (i = 0; i < cache->filters->len; i ++) {
- it = g_ptr_array_index (cache->filters, i);
+ PTR_ARRAY_FOREACH (cache->items_by_id, i, it) {
- for (j = 0; j < it->deps->len; j ++) {
- dep = g_ptr_array_index (it->deps, j);
+ PTR_ARRAY_FOREACH (it->deps, j, dep) {
dit = rspamd_symcache_find_filter (cache, dep->sym);
if (dit != NULL) {
}
}
- /* Reversed loop to make removal safe */
- for (j = it->deps->len - 1; j >= 0; j --) {
- dep = g_ptr_array_index (it->deps, j);
+ if (it->deps) {
+ /* Reversed loop to make removal safe */
+ for (j = it->deps->len - 1; j >= 0; j--) {
+ dep = g_ptr_array_index (it->deps, j);
- if (dep->item == NULL) {
- /* Remove useless dep */
- g_ptr_array_remove_index (it->deps, j);
+ if (dep->item == NULL) {
+ /* Remove useless dep */
+ g_ptr_array_remove_index (it->deps, j);
+ }
}
}
}
}
if (item->is_virtual) {
- g_assert (item->specific.virtual.parent < (gint)cache->filters->len);
- parent = g_ptr_array_index (cache->filters,
+ g_assert (item->specific.virtual.parent < (gint)cache->items_by_id->len);
+ parent = g_ptr_array_index (cache->items_by_id,
item->specific.virtual.parent);
if (parent->st->weight < item->st->weight) {
item->specific.virtual.parent = parent;
item->id = cache->virtual->len;
g_ptr_array_add (cache->virtual, item);
+ /* Not added to items_by_id, handled by parent */
}
}
}
if (item->is_virtual) {
- g_assert (item->specific.virtual.parent < (gint)cache->filters->len);
- parent = g_ptr_array_index (cache->filters,
+ g_assert (item->specific.virtual.parent < (gint)cache->items_by_id->len);
+ parent = g_ptr_array_index (cache->items_by_id,
item->specific.virtual.parent);
if (fabs (parent->st->weight) < fabs (item->st->weight)) {
"symbol", 0, false);
if (item->is_virtual) {
- parent = g_ptr_array_index (cbd->cache->filters,
+ parent = g_ptr_array_index (cbd->cache->items_by_id,
item->specific.virtual.parent);
ucl_object_insert_key (obj,
ucl_object_fromdouble (ROUND_DOUBLE (item->st->weight)),
struct rspamd_symcache_item *source;
struct cache_dependency *dep;
- g_assert (id_from >= 0 && id_from < (gint)cache->filters->len);
+ g_assert (id_from >= 0 && id_from < (gint)cache->items_by_id->len);
- source = g_ptr_array_index (cache->filters, id_from);
+ source = g_ptr_array_index (cache->items_by_id, id_from);
dep = rspamd_mempool_alloc (cache->static_pool, sizeof (*dep));
dep->id = id_from;
dep->sym = rspamd_mempool_strdup (cache->static_pool, to);
g_assert (cache != NULL);
- if (id < 0 || id >= (gint)cache->filters->len) {
+ if (id < 0 || id >= (gint)cache->items_by_id->len) {
return NULL;
}
- item = g_ptr_array_index (cache->filters, id);
+ item = g_ptr_array_index (cache->items_by_id, id);
return item->symbol;
}