From 02a1615e2d131b26456fef704e4da73e00a3f8d7 Mon Sep 17 00:00:00 2001 From: Paul Ferrand Date: Tue, 6 Oct 2020 23:03:25 +0200 Subject: [PATCH] Use the back inserter idiom in all stealing methods --- src/sfizz/Synth.cpp | 23 +++++++---------------- 1 file changed, 7 insertions(+), 16 deletions(-) diff --git a/src/sfizz/Synth.cpp b/src/sfizz/Synth.cpp index 245a7240..2348dcb4 100644 --- a/src/sfizz/Synth.cpp +++ b/src/sfizz/Synth.cpp @@ -1024,12 +1024,9 @@ void sfz::Synth::noteOffDispatch(int delay, int noteNumber, float velocity) noex void sfz::Synth::checkRegionPolyphony(const Region* region, int delay) noexcept { tempPolyphonyArray.clear(); - - for (Voice* voice : voiceViewArray) { - if (voice->getRegion() == region && !voice->releasedOrFree()) { - tempPolyphonyArray.push_back(voice); - } - } + absl::c_copy_if(voiceViewArray, + std::back_inserter(tempPolyphonyArray), + [region](Voice* v) { return v->getRegion() == region && !v->releasedOrFree(); }); if (tempPolyphonyArray.size() >= region->polyphony) { const auto voiceToSteal = stealer.steal(absl::MakeSpan(tempPolyphonyArray)); @@ -1078,11 +1075,8 @@ void sfz::Synth::checkGroupPolyphony(const Region* region, int delay) noexcept { const auto& activeVoices = polyphonyGroups[region->group].getActiveVoices(); tempPolyphonyArray.clear(); - for (Voice* voice : activeVoices) { - if (!voice->releasedOrFree()) { - tempPolyphonyArray.push_back(voice); - } - } + absl::c_copy_if(activeVoices, + std::back_inserter(tempPolyphonyArray), [](Voice* v) { return !v->releasedOrFree(); }); if (tempPolyphonyArray.size() >= polyphonyGroups[region->group].getPolyphonyLimit()) { const auto voiceToSteal = stealer.steal(absl::MakeSpan(tempPolyphonyArray)); @@ -1096,11 +1090,8 @@ void sfz::Synth::checkSetPolyphony(const Region* region, int delay) noexcept while (parent != nullptr) { const auto& activeVoices = parent->getActiveVoices(); tempPolyphonyArray.clear(); - for (Voice* voice : activeVoices) { - if (!voice->releasedOrFree()) { - tempPolyphonyArray.push_back(voice); - } - } + absl::c_copy_if(activeVoices, + std::back_inserter(tempPolyphonyArray), [](Voice* v) { return !v->releasedOrFree(); }); if (tempPolyphonyArray.size() >= parent->getPolyphonyLimit()) { const auto voiceToSteal = stealer.steal(absl::MakeSpan(tempPolyphonyArray));