Skip to content

Commit

Permalink
ValueTree: Optimise when listeners don't remove themselves
Browse files Browse the repository at this point in the history
  • Loading branch information
Anthony-Nicholls committed Jun 7, 2024
1 parent a469daf commit 315167a
Showing 1 changed file with 9 additions and 11 deletions.
20 changes: 9 additions & 11 deletions modules/juce_data_structures/values/juce_ValueTree.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,23 +76,21 @@ class ValueTree::SharedObject final : public ReferenceCountedObject
template <typename Function>
void callListeners (ValueTree::Listener* listenerToExclude, Function fn) const
{
auto numListeners = valueTreesWithListeners.size();
if (valueTreesWithListeners.size() == 0)
return;

if (numListeners == 1)
if (valueTreesWithListeners.size() == 1)
{
valueTreesWithListeners.getUnchecked (0)->listeners.callExcluding (listenerToExclude, fn);
return;
}
else if (numListeners > 0)
{
auto listenersCopy = valueTreesWithListeners;

for (int i = 0; i < numListeners; ++i)
{
auto* v = listenersCopy.getUnchecked (i);
const auto listenersCopy = valueTreesWithListeners;

if (i == 0 || valueTreesWithListeners.contains (v))
v->listeners.callExcluding (listenerToExclude, fn);
}
for (auto [i, v] : enumerate (listenersCopy, int{}))
{
if (valueTreesWithListeners[i] == v || valueTreesWithListeners.contains (v))
v->listeners.callExcluding (listenerToExclude, fn);
}
}

Expand Down

0 comments on commit 315167a

Please sign in to comment.