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 | |
parent | db01d290e7c95bd147a297e4996171e76908c9aa (diff) |
add support for mempool/linklist functions.
Diffstat (limited to 'source/blender/blenlib')
-rw-r--r-- | source/blender/blenlib/BLI_linklist.h | 5 | ||||
-rw-r--r-- | source/blender/blenlib/intern/BLI_linklist.c | 47 |
2 files changed, 52 insertions, 0 deletions
diff --git a/source/blender/blenlib/BLI_linklist.h b/source/blender/blenlib/BLI_linklist.h index 3e7fdc8bf75..9c1e1f88bab 100644 --- a/source/blender/blenlib/BLI_linklist.h +++ b/source/blender/blenlib/BLI_linklist.h @@ -36,6 +36,7 @@ */ struct MemArena; +struct BLI_mempool; typedef void (*LinkNodeFreeFP)(void *link); typedef void (*LinkNodeApplyFP)(void *link, void *userdata); @@ -56,10 +57,14 @@ void BLI_linklist_reverse(struct LinkNode **listp); void BLI_linklist_prepend(struct LinkNode **listp, void *ptr); void BLI_linklist_append(struct LinkNode **listp, void *ptr); void BLI_linklist_prepend_arena(struct LinkNode **listp, void *ptr, struct MemArena *ma); +void BLI_linklist_prepend_pool(struct LinkNode **listp, void *ptr, struct BLI_mempool *mempool); +void *BLI_linklist_pop(struct LinkNode **listp); +void *BLI_linklist_pop_pool(struct LinkNode **listp, struct BLI_mempool *mempool); void BLI_linklist_insert_after(struct LinkNode **listp, void *ptr); void BLI_linklist_free(struct LinkNode *list, LinkNodeFreeFP freefunc); void BLI_linklist_freeN(struct LinkNode *list); +void BLI_linklist_free_pool(LinkNode *list, LinkNodeFreeFP freefunc, struct BLI_mempool *mempool); void BLI_linklist_apply(struct LinkNode *list, LinkNodeApplyFP applyfunc, void *userdata); #endif 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) { |