From b51d43d8246404238ab5b47b47ba4ccb98688f73 Mon Sep 17 00:00:00 2001 From: jules Date: Mon, 6 Nov 2017 11:05:51 +0000 Subject: [PATCH] Converted a couple of lambdas to functors due to FUD about compilers generating heap allocations --- modules/juce_audio_basics/mpe/juce_MPESynthesiser.cpp | 11 +++++++++-- .../synthesisers/juce_Synthesiser.cpp | 11 +++++++++-- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/modules/juce_audio_basics/mpe/juce_MPESynthesiser.cpp b/modules/juce_audio_basics/mpe/juce_MPESynthesiser.cpp index 2cf1cce626..ac519c494b 100644 --- a/modules/juce_audio_basics/mpe/juce_MPESynthesiser.cpp +++ b/modules/juce_audio_basics/mpe/juce_MPESynthesiser.cpp @@ -202,8 +202,15 @@ MPESynthesiserVoice* MPESynthesiser::findVoiceToSteal (MPENote noteToStealVoiceF jassert (voice->isActive()); // We wouldn't be here otherwise usableVoices.add (voice); - std::sort (usableVoices.begin(), usableVoices.end(), - [] (const MPESynthesiserVoice* a, const MPESynthesiserVoice* b) { return a->wasStartedBefore (*b); }); + + // NB: Using a functor rather than a lambda here due to scare-stories about + // compilers generating code containing heap allocations.. + struct Sorter + { + bool operator() (const MPESynthesiserVoice* a, const MPESynthesiserVoice* b) const noexcept { return a->wasStartedBefore (*b); } + }; + + std::sort (usableVoices.begin(), usableVoices.end(), Sorter()); if (! voice->isPlayingButReleased()) // Don't protect released notes { diff --git a/modules/juce_audio_basics/synthesisers/juce_Synthesiser.cpp b/modules/juce_audio_basics/synthesisers/juce_Synthesiser.cpp index 36c814f561..fa047d1496 100644 --- a/modules/juce_audio_basics/synthesisers/juce_Synthesiser.cpp +++ b/modules/juce_audio_basics/synthesisers/juce_Synthesiser.cpp @@ -514,8 +514,15 @@ SynthesiserVoice* Synthesiser::findVoiceToSteal (SynthesiserSound* soundToPlay, jassert (voice->isVoiceActive()); // We wouldn't be here otherwise usableVoices.add (voice); - std::sort (usableVoices.begin(), usableVoices.end(), - [] (const SynthesiserVoice* a, const SynthesiserVoice* b) { return a->wasStartedBefore (*b); }); + + // NB: Using a functor rather than a lambda here due to scare-stories about + // compilers generating code containing heap allocations.. + struct Sorter + { + bool operator() (const SynthesiserVoice* a, const SynthesiserVoice* b) const noexcept { return a->wasStartedBefore (*b); } + }; + + std::sort (usableVoices.begin(), usableVoices.end(), Sorter()); if (! voice->isPlayingButReleased()) // Don't protect released notes {