diff options
Diffstat (limited to 'source/blender/blenlib')
-rw-r--r-- | source/blender/blenlib/BLI_linklist.h | 13 | ||||
-rw-r--r-- | source/blender/blenlib/intern/BLI_linklist.c | 49 |
2 files changed, 46 insertions, 16 deletions
diff --git a/source/blender/blenlib/BLI_linklist.h b/source/blender/blenlib/BLI_linklist.h index 9c1e1f88bab..2ca363ee780 100644 --- a/source/blender/blenlib/BLI_linklist.h +++ b/source/blender/blenlib/BLI_linklist.h @@ -54,10 +54,16 @@ struct LinkNode *BLI_linklist_find(struct LinkNode *list, int index); void BLI_linklist_reverse(struct LinkNode **listp); +void BLI_linklist_prepend_nlink(struct LinkNode **listp, void *ptr, struct LinkNode *nlink); 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_append_nlink(LinkNode **listp, void *ptr, LinkNode *nlink); +void BLI_linklist_append(struct LinkNode **listp, void *ptr); +void BLI_linklist_append_arena(LinkNode **listp, void *ptr, struct MemArena *ma); +void BLI_linklist_append_pool(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); @@ -67,4 +73,7 @@ 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 +#define BLI_linklist_prepend_alloca(listp, ptr) \ + BLI_linklist_prepend_nlink(listp, ptr, alloca(sizeof(LinkNode))) + +#endif /* __BLI_LINKLIST_H__ */ diff --git a/source/blender/blenlib/intern/BLI_linklist.c b/source/blender/blenlib/intern/BLI_linklist.c index 99fc5f27726..66fcfd21fbb 100644 --- a/source/blender/blenlib/intern/BLI_linklist.c +++ b/source/blender/blenlib/intern/BLI_linklist.c @@ -89,18 +89,39 @@ void BLI_linklist_reverse(LinkNode **listp) *listp = rhead; } -void BLI_linklist_prepend(LinkNode **listp, void *ptr) +/** + * A version of prepend that takes the allocated link. + */ +void BLI_linklist_prepend_nlink(LinkNode **listp, void *ptr, LinkNode *nlink) { - LinkNode *nlink = MEM_mallocN(sizeof(*nlink), "nlink"); nlink->link = ptr; - nlink->next = *listp; *listp = nlink; } -void BLI_linklist_append(LinkNode **listp, void *ptr) +void BLI_linklist_prepend(LinkNode **listp, void *ptr) { LinkNode *nlink = MEM_mallocN(sizeof(*nlink), "nlink"); + BLI_linklist_prepend_nlink(listp, ptr, nlink); +} + +void BLI_linklist_prepend_arena(LinkNode **listp, void *ptr, MemArena *ma) +{ + LinkNode *nlink = BLI_memarena_alloc(ma, sizeof(*nlink)); + BLI_linklist_prepend_nlink(listp, ptr, nlink); +} + +void BLI_linklist_prepend_pool(LinkNode **listp, void *ptr, BLI_mempool *mempool) +{ + LinkNode *nlink = BLI_mempool_alloc(mempool); + BLI_linklist_prepend_nlink(listp, ptr, nlink); +} + +/** + * A version of append that takes the allocated link. + */ +void BLI_linklist_append_nlink(LinkNode **listp, void *ptr, LinkNode *nlink) +{ LinkNode *node = *listp; nlink->link = ptr; @@ -117,22 +138,22 @@ void BLI_linklist_append(LinkNode **listp, void *ptr) } } -void BLI_linklist_prepend_arena(LinkNode **listp, void *ptr, MemArena *ma) +void BLI_linklist_append(LinkNode **listp, void *ptr) +{ + LinkNode *nlink = MEM_mallocN(sizeof(*nlink), "nlink"); + BLI_linklist_append_nlink(listp, ptr, nlink); +} + +void BLI_linklist_append_arena(LinkNode **listp, void *ptr, MemArena *ma) { LinkNode *nlink = BLI_memarena_alloc(ma, sizeof(*nlink)); - nlink->link = ptr; - - nlink->next = *listp; - *listp = nlink; + BLI_linklist_append_nlink(listp, ptr, nlink); } -void BLI_linklist_prepend_pool(LinkNode **listp, void *ptr, BLI_mempool *mempool) +void BLI_linklist_append_pool(LinkNode **listp, void *ptr, BLI_mempool *mempool) { LinkNode *nlink = BLI_mempool_alloc(mempool); - nlink->link = ptr; - - nlink->next = *listp; - *listp = nlink; + BLI_linklist_append_nlink(listp, ptr, nlink); } void *BLI_linklist_pop(struct LinkNode **listp) |