diff options
author | Chris Robinson <[email protected]> | 2020-02-21 00:54:05 -0800 |
---|---|---|
committer | Chris Robinson <[email protected]> | 2020-02-21 00:54:05 -0800 |
commit | 9b801227d5108f9b74bf94df49e7c341f0809c94 (patch) | |
tree | 306b32741e36afad788b0eecf412d44d873b49c6 /al/source.cpp | |
parent | 9b43327f56649fb46ed0b939ac05ff6c95d1a998 (diff) |
Don't unnecessarily count all voices when playing sources
Diffstat (limited to 'al/source.cpp')
-rw-r--r-- | al/source.cpp | 17 |
1 files changed, 8 insertions, 9 deletions
diff --git a/al/source.cpp b/al/source.cpp index 2b474e89..d62649b6 100644 --- a/al/source.cpp +++ b/al/source.cpp @@ -2725,17 +2725,16 @@ START_API_FUNC } /* Count the number of reusable voices. */ - auto count_free_voices = [](const ALuint count, const ALvoice &voice) noexcept -> ALuint + size_t free_voices{0}; + for(const ALvoice &voice : context->mVoices) { - if(voice.mPlayState.load(std::memory_order_acquire) == ALvoice::Stopped + free_voices += (voice.mPlayState.load(std::memory_order_acquire) == ALvoice::Stopped && voice.mSourceID.load(std::memory_order_relaxed) == 0u - && voice.mPendingStop.load(std::memory_order_relaxed) == false) - return count + 1; - return count; - }; - auto free_voices = std::accumulate(context->mVoices.begin(), context->mVoices.end(), - ALuint{0}, count_free_voices); - if UNLIKELY(srchandles.size() > free_voices) + && voice.mPendingStop.load(std::memory_order_relaxed) == false); + if(free_voices == srchandles.size()) + break; + } + if UNLIKELY(srchandles.size() != free_voices) { /* Increase the number of voices to handle the request. */ const size_t need_voices{srchandles.size() - free_voices}; |