diff options
author | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2017-01-18 16:48:51 +0000 |
---|---|---|
committer | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2017-01-18 16:48:51 +0000 |
commit | 9d090bfa97a3de12fbc6123def434609349b9031 (patch) | |
tree | 27c685ece7192e2453dcf822398afdda40093bd1 /src/libutil | |
parent | 9886b3d1a4e1d823a29b8f420766f2dc82c5a2fc (diff) | |
download | rspamd-9d090bfa97a3de12fbc6123def434609349b9031.tar.gz rspamd-9d090bfa97a3de12fbc6123def434609349b9031.zip |
[Minor] Add mempool functions to work with glists
Diffstat (limited to 'src/libutil')
-rw-r--r-- | src/libutil/mem_pool.c | 42 | ||||
-rw-r--r-- | src/libutil/mem_pool.h | 16 |
2 files changed, 58 insertions, 0 deletions
diff --git a/src/libutil/mem_pool.c b/src/libutil/mem_pool.c index 3b05e1d59..1ee0558a1 100644 --- a/src/libutil/mem_pool.c +++ b/src/libutil/mem_pool.c @@ -874,3 +874,45 @@ rspamd_mempool_remove_variable (rspamd_mempool_t *pool, const gchar *name) g_hash_table_remove (pool->variables, name); } } + +GList * +rspamd_mempool_glist_prepend (rspamd_mempool_t *pool, GList *l, gpointer p) +{ + GList *cell; + + cell = rspamd_mempool_alloc (pool, sizeof (*cell)); + cell->prev = NULL; + cell->data = p; + + if (l == NULL) { + cell->next = NULL; + } + else { + cell->next = l; + l->prev = cell; + } + + return cell; +} + +GList * +rspamd_mempool_glist_append (rspamd_mempool_t *pool, GList *l, gpointer p) +{ + GList *cell, *cur; + + cell = rspamd_mempool_alloc (pool, sizeof (*cell)); + cell->next = NULL; + cell->data = p; + + if (l) { + for (cur = l; cur->next != NULL; cur = cur->next) {} + cur->next = cell; + cell->prev = cur; + } + else { + l = cell; + l->prev = NULL; + } + + return l; +} diff --git a/src/libutil/mem_pool.h b/src/libutil/mem_pool.h index 69e9f6437..f16d454f2 100644 --- a/src/libutil/mem_pool.h +++ b/src/libutil/mem_pool.h @@ -320,5 +320,21 @@ gpointer rspamd_mempool_get_variable (rspamd_mempool_t *pool, */ void rspamd_mempool_remove_variable (rspamd_mempool_t *pool, const gchar *name); +/** + * Prepend element to a list creating it in the memory pool + * @param l + * @param p + * @return + */ +GList *rspamd_mempool_glist_prepend (rspamd_mempool_t *pool, + GList *l, gpointer p) G_GNUC_WARN_UNUSED_RESULT; +/** + * Append element to a list creating it in the memory pool + * @param l + * @param p + * @return + */ +GList *rspamd_mempool_glist_append (rspamd_mempool_t *pool, + GList *l, gpointer p) G_GNUC_WARN_UNUSED_RESULT; #endif |