From 3403f502afb5921f3295a4f5e4e7676b8a30e00e Mon Sep 17 00:00:00 2001 From: Tim Blechmann Date: Wed, 12 Sep 2012 10:37:50 +0200 Subject: [PATCH] supernova: avoid duplicate traversal of children on group_free Signed-off-by: Tim Blechmann --- server/supernova/server/group.hpp | 16 ---------------- server/supernova/server/node_graph.hpp | 16 +++++++++------- 2 files changed, 9 insertions(+), 23 deletions(-) diff --git a/server/supernova/server/group.hpp b/server/supernova/server/group.hpp index 0c2acfbb0..aec05eb2f 100644 --- a/server/supernova/server/group.hpp +++ b/server/supernova/server/group.hpp @@ -127,22 +127,6 @@ public: return child_synth_count + child_group_count; } - /* number of child synths and groups */ - std::pair child_count_deep(void) const - { - std::size_t synths = child_synth_count; - std::size_t groups = child_group_count; - - for (group_list::const_iterator it = child_groups.begin(); it != child_groups.end(); ++it) - { - std::size_t recursive_synths, recursive_groups; - boost::tie(recursive_synths, recursive_groups) = it->child_count_deep(); - groups += recursive_groups; - synths += recursive_synths; - } - return std::make_pair(synths, groups); - } - template void apply_on_children(functor const & f) { diff --git a/server/supernova/server/node_graph.hpp b/server/supernova/server/node_graph.hpp index 39149ee16..858b49454 100644 --- a/server/supernova/server/node_graph.hpp +++ b/server/supernova/server/node_graph.hpp @@ -127,13 +127,15 @@ public: bool group_free_all(abstract_group * group) { + size_t synths = 0, groups = 0; group->apply_deep_on_children([&](server_node & node) { release_node_id(&node); + if (node.is_synth()) + synths += 1; + else + groups += 1; }); - size_t synths, groups; - boost::tie(synths, groups) = group->child_count_deep(); - group->free_children(); synth_count_ -= synths; group_count_ -= groups; @@ -142,14 +144,14 @@ public: bool group_free_deep(abstract_group * group) { + size_t synths; group->apply_deep_on_children([&](server_node & node) { - if (node.is_synth()) + if (node.is_synth()) { release_node_id(&node); + synths += 1; + } }); - size_t synths, groups; - boost::tie(synths, groups) = group->child_count_deep(); - group->free_synths_deep(); synth_count_ -= synths; return true; -- 2.11.4.GIT