Browse Source

Converted a couple of lambdas to functors due to FUD about compilers generating heap allocations

tags/2021-05-28
jules 7 years ago
parent
commit
b51d43d824
2 changed files with 18 additions and 4 deletions
  1. +9
    -2
      modules/juce_audio_basics/mpe/juce_MPESynthesiser.cpp
  2. +9
    -2
      modules/juce_audio_basics/synthesisers/juce_Synthesiser.cpp

+ 9
- 2
modules/juce_audio_basics/mpe/juce_MPESynthesiser.cpp View File

@@ -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
{


+ 9
- 2
modules/juce_audio_basics/synthesisers/juce_Synthesiser.cpp View File

@@ -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
{


Loading…
Cancel
Save