[Bf-blender-cvs] [f27acb5] master: ListBase: add BLI_sortlist_r api function, remove check for NULL callback
Campbell Barton
noreply at git.blender.org
Thu Feb 13 03:21:31 CET 2014
Commit: f27acb5b560f3cd39c5e763f4cd2b1af52ca9072
Author: Campbell Barton
Date: Thu Feb 13 13:08:05 2014 +1100
https://developer.blender.org/rBf27acb5b560f3cd39c5e763f4cd2b1af52ca9072
ListBase: add BLI_sortlist_r api function, remove check for NULL callback
===================================================================
M source/blender/blenlib/BLI_listbase.h
M source/blender/blenlib/intern/listbase.c
===================================================================
diff --git a/source/blender/blenlib/BLI_listbase.h b/source/blender/blenlib/BLI_listbase.h
index a54fa15..6d96d4d 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 2c59b94..17e7bf8 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.
More information about the Bf-blender-cvs
mailing list