diff options
author | Campbell Barton <ideasman42@gmail.com> | 2013-08-16 09:50:00 +0400 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2013-08-16 09:50:00 +0400 |
commit | 763c205e7243d54f2d06d0031dd6b370a603c759 (patch) | |
tree | 9d62dd5a960c3dbec363de0e91dba144b19a24a6 /source/blender/blenlib/intern/BLI_linklist.c | |
parent | db01d290e7c95bd147a297e4996171e76908c9aa (diff) |
add support for mempool/linklist functions.
Diffstat (limited to 'source/blender/blenlib/intern/BLI_linklist.c')
-rw-r--r-- | source/blender/blenlib/intern/BLI_linklist.c | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/source/blender/blenlib/intern/BLI_linklist.c b/source/blender/blenlib/intern/BLI_linklist.c index b08fbe17a43..99fc5f27726 100644 --- a/source/blender/blenlib/intern/BLI_linklist.c +++ b/source/blender/blenlib/intern/BLI_linklist.c @@ -34,6 +34,7 @@ #include "MEM_guardedalloc.h" #include "BLI_linklist.h" #include "BLI_memarena.h" +#include "BLI_mempool.h" int BLI_linklist_length(LinkNode *list) { @@ -125,6 +126,39 @@ void BLI_linklist_prepend_arena(LinkNode **listp, void *ptr, MemArena *ma) *listp = nlink; } +void BLI_linklist_prepend_pool(LinkNode **listp, void *ptr, BLI_mempool *mempool) +{ + LinkNode *nlink = BLI_mempool_alloc(mempool); + nlink->link = ptr; + + nlink->next = *listp; + *listp = nlink; +} + +void *BLI_linklist_pop(struct LinkNode **listp) +{ + /* intentionally no NULL check */ + void *link = (*listp)->link; + void *next = (*listp)->next; + + MEM_freeN((*listp)); + + *listp = next; + return link; +} + +void *BLI_linklist_pop_pool(struct LinkNode **listp, struct BLI_mempool *mempool) +{ + /* intentionally no NULL check */ + void *link = (*listp)->link; + void *next = (*listp)->next; + + BLI_mempool_free(mempool, (*listp)); + + *listp = next; + return link; +} + void BLI_linklist_insert_after(LinkNode **listp, void *ptr) { LinkNode *nlink = MEM_mallocN(sizeof(*nlink), "nlink"); @@ -155,6 +189,19 @@ void BLI_linklist_free(LinkNode *list, LinkNodeFreeFP freefunc) } } +void BLI_linklist_free_pool(LinkNode *list, LinkNodeFreeFP freefunc, struct BLI_mempool *mempool) +{ + while (list) { + LinkNode *next = list->next; + + if (freefunc) + freefunc(list->link); + BLI_mempool_free(mempool, list); + + list = next; + } +} + void BLI_linklist_freeN(LinkNode *list) { while (list) { |