From d06ed618d356a713292de95f0ab2c6017c305e17 Mon Sep 17 00:00:00 2001 From: Chris Robinson Date: Tue, 22 Feb 2022 03:03:44 -0800 Subject: Avoid using an if_constexpr macro It doesn't actually use if constexpr, and compilers are smart enough to optimize. Some functions can use templates instead. --- alc/backends/wave.cpp | 22 ++++++++-------------- 1 file changed, 8 insertions(+), 14 deletions(-) (limited to 'alc/backends/wave.cpp') diff --git a/alc/backends/wave.cpp b/alc/backends/wave.cpp index db3d1151..6360166c 100644 --- a/alc/backends/wave.cpp +++ b/alc/backends/wave.cpp @@ -149,29 +149,23 @@ int WaveBackend::mixerProc() mDevice->renderSamples(mBuffer.data(), mDevice->UpdateSize, frameStep); done += mDevice->UpdateSize; - if_constexpr(al::endian::native != al::endian::little) + if(al::endian::native != al::endian::little) { const uint bytesize{mDevice->bytesFromFmt()}; if(bytesize == 2) { - ushort *samples = reinterpret_cast(mBuffer.data()); - const size_t len{mBuffer.size() / 2}; - for(size_t i{0};i < len;i++) - { - const ushort samp{samples[i]}; - samples[i] = static_cast((samp>>8) | (samp<<8)); - } + const size_t len{mBuffer.size() & ~size_t{1}}; + for(size_t i{0};i < len;i+=2) + std::swap(mBuffer[i], mBuffer[i+1]); } else if(bytesize == 4) { - uint *samples = reinterpret_cast(mBuffer.data()); - const size_t len{mBuffer.size() / 4}; - for(size_t i{0};i < len;i++) + const size_t len{mBuffer.size() & ~size_t{3}}; + for(size_t i{0};i < len;i+=4) { - const uint samp{samples[i]}; - samples[i] = (samp>>24) | ((samp>>8)&0x0000ff00) | - ((samp<<8)&0x00ff0000) | (samp<<24); + std::swap(mBuffer[i ], mBuffer[i+3]); + std::swap(mBuffer[i+1], mBuffer[i+2]); } } } -- cgit v1.2.3