From: Vsevolod Stakhov Date: Wed, 18 Jan 2017 16:48:51 +0000 (+0000) Subject: [Minor] Add mempool functions to work with glists X-Git-Tag: 1.5.0~308 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=9d090bfa97a3de12fbc6123def434609349b9031;p=thirdparty%2Frspamd.git [Minor] Add mempool functions to work with glists --- diff --git a/src/libutil/mem_pool.c b/src/libutil/mem_pool.c index 3b05e1d59b..1ee0558a19 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 69e9f64377..f16d454f2f 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