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
This commit is contained in:
2021-08-20 16:30:34 +02:00
parent 796035ad93
commit f49d438ced
28 changed files with 918 additions and 738 deletions

View File

@@ -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;
}