/* Get a proper queue */
TAILQ_INSERT_TAIL (&expire->head, elt, entry);
- //msg_info ("insert elt: %p", elt);
}
/**
* Delete an element from expire queue
else {
g_slice_free1 (ELT_SIZE (oldest_elt), oldest_elt);
}
- //msg_info ("remove elt: %p, prev: %p, next: %p", oldest_elt, TAILQ_PREV (oldest_elt, eltq, entry), TAILQ_NEXT (oldest_elt, entry));
}
return TRUE;
if ((elt = g_hash_table_lookup (cache->hash, key)) == NULL) {
keylen = strlen (key);
- elt = g_slice_alloc0 (sizeof (struct rspamd_kv_element) + len + keylen + 1);
+ elt = g_slice_alloc (sizeof (struct rspamd_kv_element) + len + keylen + 1);
elt->age = time (NULL);
elt->keylen = keylen;
elt->size = len;
g_slice_free1 (ELT_SIZE (elt), elt);
}
keylen = strlen (key);
- elt = g_slice_alloc0 (sizeof (struct rspamd_kv_element) + len + keylen + 1);
+ elt = g_slice_alloc (sizeof (struct rspamd_kv_element) + len + keylen + 1);
elt->age = time (NULL);
elt->keylen = keylen;
elt->size = len;
if (rkey == 0) {
return NULL;
}
+
elt = (struct rspamd_kv_element *)radix32tree_find (cache->tree, rkey);
if ((uintptr_t)elt == RADIX_NO_VALUE) {
keylen = strlen (key);
- elt = g_slice_alloc0 (sizeof (struct rspamd_kv_element) + len + keylen + 1);
+ elt = g_slice_alloc (sizeof (struct rspamd_kv_element) + len + keylen + 1);
elt->age = time (NULL);
+ elt->keylen = keylen;
+ elt->size = len;
+ elt->hash = rkey;
+ memcpy (elt->data, key, keylen + 1);
+ memcpy (ELT_DATA (elt), value, len);
+ radix32tree_insert (cache->tree, rkey, 0xffffffff, (uintptr_t)elt);
+ }
+ else {
+ radix32tree_delete (cache->tree, rkey, 0xffffffff);
+ if ((elt->flags & KV_ELT_DIRTY) != 0) {
+ elt->flags |= KV_ELT_NEED_FREE;
+ }
+ else {
+ /* Free it by self */
+ g_slice_free1 (ELT_SIZE (elt), elt);
+ }
+ keylen = strlen (key);
+ elt = g_slice_alloc (sizeof (struct rspamd_kv_element) + len + keylen + 1);
+ elt->age = time (NULL);
+ elt->keylen = keylen;
elt->size = len;
elt->hash = rkey;
memcpy (elt->data, key, keylen + 1);
{
struct rspamd_kv_radix_cache *cache = (struct rspamd_kv_radix_cache *)c;
guint32 rkey = rspamd_kv_radix_validate (key);
+ struct rspamd_kv_element *oldelt;
- radix32tree_replace (cache->tree, rkey, 0xffffffff, (uintptr_t)elt);
+ oldelt = (struct rspamd_kv_element *)radix32tree_find (cache->tree, rkey);
+ if ((uintptr_t)oldelt != RADIX_NO_VALUE) {
+ radix32tree_delete (cache->tree, rkey, 0xffffffff);
- return TRUE;
+ if ((oldelt->flags & KV_ELT_DIRTY) != 0) {
+ oldelt->flags |= KV_ELT_NEED_FREE;
+ }
+ else {
+ /* Free it by self */
+ g_slice_free1 (ELT_SIZE (oldelt), oldelt);
+ }
+ radix32tree_insert (cache->tree, rkey, 0xffffffff, (uintptr_t)elt);
+ return TRUE;
+ }
+
+ return FALSE;
}
/**
if ((elt = rspamd_kv_judy_lookup (c, key)) == NULL) {
keylen = strlen (key);
- elt = g_slice_alloc0 (sizeof (struct rspamd_kv_element) + len + keylen + 1);
+ elt = g_slice_alloc (sizeof (struct rspamd_kv_element) + len + keylen + 1);
elt->age = time (NULL);
elt->keylen = keylen;
elt->size = len;