diff options
author | Campbell Barton <ideasman42@gmail.com> | 2014-02-13 06:08:05 +0400 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2014-02-13 06:21:16 +0400 |
commit | f27acb5b560f3cd39c5e763f4cd2b1af52ca9072 (patch) | |
tree | 799cc347e7e1898a66e3c9f1e50887d78c81a537 /source/blender/blenlib/intern/listbase.c | |
parent | fdcdd5e52efcbc893cbf251fe0090af9e04aa090 (diff) |
ListBase: add BLI_sortlist_r api function, remove check for NULL callback
Diffstat (limited to 'source/blender/blenlib/intern/listbase.c')
-rw-r--r-- | source/blender/blenlib/intern/listbase.c | 24 |
1 files changed, 22 insertions, 2 deletions
diff --git a/source/blender/blenlib/intern/listbase.c b/source/blender/blenlib/intern/listbase.c index 2c59b940f8c..17e7bf8a99b 100644 --- a/source/blender/blenlib/intern/listbase.c +++ b/source/blender/blenlib/intern/listbase.c @@ -178,8 +178,6 @@ void BLI_sortlist(ListBase *listbase, int (*cmp)(void *, void *)) Link *current = NULL; Link *previous = NULL; Link *next = NULL; - - if (cmp == NULL) return; if (listbase->first != listbase->last) { for (previous = listbase->first, current = previous->next; current; current = next) { @@ -197,6 +195,28 @@ void BLI_sortlist(ListBase *listbase, int (*cmp)(void *, void *)) } } +void BLI_sortlist_r(ListBase *listbase, void *thunk, int (*cmp)(void *, void *, void *)) +{ + Link *current = NULL; + Link *previous = NULL; + Link *next = NULL; + + if (listbase->first != listbase->last) { + for (previous = listbase->first, current = previous->next; current; current = next) { + next = current->next; + previous = current->prev; + + BLI_remlink(listbase, current); + + while (previous && cmp(thunk, previous, current) == 1) { + previous = previous->prev; + } + + BLI_insertlinkafter(listbase, previous, current); + } + } +} + /** * Inserts \a vnewlink immediately following \a vprevlink in \a listbase. * Or, if \a vprevlink is NULL, puts \a vnewlink at the front of the list. |