From 04fbc328e98b97dab4bdbbf34494dae35b92bbd6 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Tue, 10 Sep 2019 20:20:17 -0400 Subject: [PATCH 1/2] Studio: Make _cyclicCheck a const member function This doesn't actually modify the internal state of the studio instance, so we can mark it as a const member function. --- include/amuse/Studio.hpp | 2 +- lib/Studio.cpp | 14 +++++++------- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/include/amuse/Studio.hpp b/include/amuse/Studio.hpp index 9f853f7..798fdba 100644 --- a/include/amuse/Studio.hpp +++ b/include/amuse/Studio.hpp @@ -18,7 +18,7 @@ class Studio { std::list m_studiosOut; #ifndef NDEBUG - bool _cyclicCheck(Studio* leaf); + bool _cyclicCheck(const Studio* leaf) const; #endif public: diff --git a/lib/Studio.cpp b/lib/Studio.cpp index c0e03cd..9ed132e 100644 --- a/lib/Studio.cpp +++ b/lib/Studio.cpp @@ -1,16 +1,16 @@ #include "amuse/Studio.hpp" + +#include + #include "amuse/Engine.hpp" namespace amuse { #ifndef NDEBUG -bool Studio::_cyclicCheck(Studio* leaf) { - for (auto it = m_studiosOut.begin(); it != m_studiosOut.end();) { - if (leaf == it->m_targetStudio.get() || it->m_targetStudio->_cyclicCheck(leaf)) - return true; - ++it; - } - return false; +bool Studio::_cyclicCheck(const Studio* leaf) const { + return std::any_of(m_studiosOut.cbegin(), m_studiosOut.cend(), [leaf](const auto& studio) { + return leaf == studio.m_targetStudio.get() || studio.m_targetStudio->_cyclicCheck(leaf); + }); } #endif From b92674e1270098d896b69299dfcd17058563bddf Mon Sep 17 00:00:00 2001 From: Lioncash Date: Tue, 10 Sep 2019 20:23:26 -0400 Subject: [PATCH 2/2] Studio: std::move studio instance in addStudioSend() Avoids an unnecessary atomic reference count increment and decrement --- lib/Studio.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Studio.cpp b/lib/Studio.cpp index 9ed132e..f94f3a9 100644 --- a/lib/Studio.cpp +++ b/lib/Studio.cpp @@ -20,7 +20,7 @@ Studio::Studio(Engine& engine, bool mainOut) : m_engine(engine), m_master(engine } void Studio::addStudioSend(ObjToken studio, float dry, float auxA, float auxB) { - m_studiosOut.emplace_back(studio, dry, auxA, auxB); + m_studiosOut.emplace_back(std::move(studio), dry, auxA, auxB); /* Cyclic check */ assert(!_cyclicCheck(this));