Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/source
diff options
context:
space:
mode:
authorCampbell Barton <ideasman42@gmail.com>2014-02-13 06:08:05 +0400
committerCampbell Barton <ideasman42@gmail.com>2014-02-13 06:21:16 +0400
commitf27acb5b560f3cd39c5e763f4cd2b1af52ca9072 (patch)
tree799cc347e7e1898a66e3c9f1e50887d78c81a537 /source
parentfdcdd5e52efcbc893cbf251fe0090af9e04aa090 (diff)
ListBase: add BLI_sortlist_r api function, remove check for NULL callback
Diffstat (limited to 'source')
-rw-r--r--source/blender/blenlib/BLI_listbase.h1
-rw-r--r--source/blender/blenlib/intern/listbase.c24
2 files changed, 23 insertions, 2 deletions
diff --git a/source/blender/blenlib/BLI_listbase.h b/source/blender/blenlib/BLI_listbase.h
index a54fa15ef4c..6d96d4dfed6 100644
--- a/source/blender/blenlib/BLI_listbase.h
+++ b/source/blender/blenlib/BLI_listbase.h
@@ -67,6 +67,7 @@ void BLI_addhead(struct ListBase *listbase, void *vlink);
void BLI_insertlinkbefore(struct ListBase *listbase, void *vnextlink, void *vnewlink);
void BLI_insertlinkafter(struct ListBase *listbase, void *vprevlink, void *vnewlink);
void BLI_sortlist(struct ListBase *listbase, int (*cmp)(void *, void *));
+void BLI_sortlist_r(ListBase *listbase, void *thunk, int (*cmp)(void *, void *, void *));
void BLI_freelist(struct ListBase *listbase);
int BLI_countlist(const struct ListBase *listbase);
void BLI_freelinkN(struct ListBase *listbase, void *vlink);
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.