[Bf-blender-cvs] [7a749eb] asset-experiments: BLI listbase: add an helper to remove a constinuous chunk of the list in a single call.

Bastien Montagne noreply at git.blender.org
Fri Mar 27 22:38:53 CET 2015


Commit: 7a749ebbcf5674960062ae1c141097555e80df02
Author: Bastien Montagne
Date:   Thu Mar 26 17:49:15 2015 +0100
Branches: asset-experiments
https://developer.blender.org/rB7a749ebbcf5674960062ae1c141097555e80df02

BLI listbase: add an helper to remove a constinuous chunk of the list in a single call.

===================================================================

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 2e01f74..7710ffc 100644
--- a/source/blender/blenlib/BLI_listbase.h
+++ b/source/blender/blenlib/BLI_listbase.h
@@ -60,6 +60,7 @@ void *BLI_rfindptr(const struct ListBase *listbase, const void *ptr, const int o
 void BLI_freelistN(struct ListBase *listbase) ATTR_NONNULL(1);
 void BLI_addtail(struct ListBase *listbase, void *vlink) ATTR_NONNULL(1);
 void BLI_remlink(struct ListBase *listbase, void *vlink) ATTR_NONNULL(1);
+void BLI_listbase_remlink_range(struct ListBase *listbase, void *vlink_start, void *vlink_end) ATTR_NONNULL(1);
 bool BLI_remlink_safe(struct ListBase *listbase, void *vlink) ATTR_NONNULL(1);
 void *BLI_pophead(ListBase *listbase) ATTR_NONNULL(1);
 void *BLI_poptail(ListBase *listbase) ATTR_NONNULL(1);
diff --git a/source/blender/blenlib/intern/listbase.c b/source/blender/blenlib/intern/listbase.c
index d52c097..53beed8 100644
--- a/source/blender/blenlib/intern/listbase.c
+++ b/source/blender/blenlib/intern/listbase.c
@@ -116,6 +116,22 @@ void BLI_remlink(ListBase *listbase, void *vlink)
 }
 
 /**
+ * Removes all links between \a vlink_start and \a vlink_end (included) from \a listbase.
+ * Assumes it is linked into there, and vlink_start is before vlink_end!
+ */
+void BLI_listbase_remlink_range(struct ListBase *listbase, void *vlink_start, void *vlink_end)
+{
+	Link *link_start = vlink_start;
+	Link *link_end = vlink_end;
+
+	if (link_end->next) link_end->next->prev = link_start->prev;
+	if (link_start->prev) link_start->prev->next = link_end->next;
+
+	if (listbase->last == link_end) listbase->last = link_start->prev;
+	if (listbase->first == link_start) listbase->first = link_end->next;
+}
+
+/**
  * Checks that \a vlink is linked into listbase, removing it from there if so.
  */
 bool BLI_remlink_safe(ListBase *listbase, void *vlink)




More information about the Bf-blender-cvs mailing list