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
diff options
context:
space:
mode:
authorSebastian Parborg <darkdefende@gmail.com>2021-08-20 17:30:34 +0300
committerSebastian Parborg <darkdefende@gmail.com>2021-08-25 18:30:39 +0300
commitf49d438ced7c5874dbf43976d9901a462176f541 (patch)
treefae7b745eaf1e793b53119f3ec27c34621727c58 /source/blender/sequencer/intern/iterator.c
parent796035ad930383c26302ab6a57e8e6c90394603b (diff)
Cleanup and remove SEQ_ALL_BEGIN macro
We now use a for_each function with callback to iterate through all sequences in the scene. This has the benefit that we now only loop over the sequences in the scene once. Before we would loop over them twice and allocate memory to store temporary data. The allocation of temporary data lead to unintentional memory leaks if the code used returns to exit out of the iteration loop. The new for_each callback method doesn't allocate any temporary data and only iterates though all sequences once. Reviewed By: Richard Antalik, Bastien Montagne Differential Revision: http://developer.blender.org/D12278
Diffstat (limited to 'source/blender/sequencer/intern/iterator.c')
-rw-r--r--source/blender/sequencer/intern/iterator.c57
1 files changed, 46 insertions, 11 deletions
diff --git a/source/blender/sequencer/intern/iterator.c b/source/blender/sequencer/intern/iterator.c
index 333a8e46c44..2ac93ccc9d3 100644
--- a/source/blender/sequencer/intern/iterator.c
+++ b/source/blender/sequencer/intern/iterator.c
@@ -90,6 +90,37 @@ Sequence *SEQ_iterator_yield(SeqIterator *iterator)
return seq;
}
+static bool seq_for_each_recursive(ListBase *seqbase, SeqForEachFunc callback, void *user_data)
+{
+ LISTBASE_FOREACH (Sequence *, seq, seqbase) {
+ if (!callback(seq, user_data)) {
+ /* Callback signaled stop, return. */
+ return false;
+ }
+ if (seq->type == SEQ_TYPE_META) {
+ if (!seq_for_each_recursive(&seq->seqbase, callback, user_data)) {
+ return false;
+ }
+ }
+ }
+ return true;
+}
+
+/**
+ * Utility function to recursivily iterate through all sequence strips in a seqbase list.
+ * Uses callback to do operations on each sequence element.
+ * The callback can stop the iteration if needed.
+ *
+ * \param seqbase: ListBase of sequences to be iterated over
+ * \param callback: query function callback, returns false if iteration should stop
+ * \param user_data: pointer to user data that can be used in the callback function
+ *
+ */
+void SEQ_for_each_callback(ListBase *seqbase, SeqForEachFunc callback, void *user_data)
+{
+ seq_for_each_recursive(seqbase, callback, user_data);
+}
+
/**
* Free strip collection.
*
@@ -222,19 +253,15 @@ void SEQ_collection_expand(ListBase *seqbase,
SeqCollection *collection))
{
/* Collect expanded results for each sequence in provided SeqIteratorCollection. */
- ListBase expand_collections = {0};
+ SeqCollection *query_matches = SEQ_collection_create(__func__);
Sequence *seq;
SEQ_ITERATOR_FOREACH (seq, collection) {
- SeqCollection *expand_collection = SEQ_query_by_reference(seq, seqbase, seq_query_func);
- BLI_addtail(&expand_collections, expand_collection);
+ SEQ_collection_merge(query_matches, SEQ_query_by_reference(seq, seqbase, seq_query_func));
}
/* Merge all expanded results in provided SeqIteratorCollection. */
- LISTBASE_FOREACH_MUTABLE (SeqCollection *, expand_collection, &expand_collections) {
- BLI_remlink(&expand_collections, expand_collection);
- SEQ_collection_merge(collection, expand_collection);
- }
+ SEQ_collection_merge(collection, query_matches);
}
/**
@@ -255,6 +282,16 @@ SeqCollection *SEQ_collection_duplicate(SeqCollection *collection)
/** \} */
+static void query_all_strips_recursive(ListBase *seqbase, SeqCollection *collection)
+{
+ LISTBASE_FOREACH (Sequence *, seq, seqbase) {
+ if (seq->type == SEQ_TYPE_META) {
+ query_all_strips_recursive(&seq->seqbase, collection);
+ }
+ SEQ_collection_append_strip(seq, collection);
+ }
+}
+
/**
* Query all strips in seqbase and nested meta strips.
*
@@ -266,7 +303,7 @@ SeqCollection *SEQ_query_all_strips_recursive(ListBase *seqbase)
SeqCollection *collection = SEQ_collection_create(__func__);
LISTBASE_FOREACH (Sequence *, seq, seqbase) {
if (seq->type == SEQ_TYPE_META) {
- SEQ_collection_merge(collection, SEQ_query_all_strips_recursive(&seq->seqbase));
+ query_all_strips_recursive(&seq->seqbase, collection);
}
SEQ_collection_append_strip(seq, collection);
}
@@ -282,9 +319,7 @@ SeqCollection *SEQ_query_all_strips_recursive(ListBase *seqbase)
SeqCollection *SEQ_query_all_strips(ListBase *seqbase)
{
SeqCollection *collection = SEQ_collection_create(__func__);
- LISTBASE_FOREACH (Sequence *, seq, seqbase) {
- SEQ_collection_append_strip(seq, collection);
- }
+ query_all_strips_recursive(seqbase, collection);
return collection;
}