From 4f32de7daf3081cf7fb93dec6c33705c5f258bed Mon Sep 17 00:00:00 2001 From: Chris Robinson Date: Sun, 12 May 2024 05:18:36 -0700 Subject: [PATCH] Pass small trivially-copyable types by value --- utils/makemhr/loaddef.cpp | 2 +- utils/makemhr/loadsofa.cpp | 2 +- utils/makemhr/makemhr.cpp | 4 ++-- utils/sofa-info.cpp | 2 +- utils/sofa-support.cpp | 2 +- utils/uhjdecoder.cpp | 5 ++--- utils/uhjencoder.cpp | 2 +- 7 files changed, 9 insertions(+), 10 deletions(-) diff --git a/utils/makemhr/loaddef.cpp b/utils/makemhr/loaddef.cpp index 7685980d..93e46923 100644 --- a/utils/makemhr/loaddef.cpp +++ b/utils/makemhr/loaddef.cpp @@ -1725,7 +1725,7 @@ auto AverageHrirOnset(PPhaseResampler &rs, al::span upsampled, const uin { rs.process(hrir, upsampled); - auto abs_lt = [](const double &lhs, const double &rhs) -> bool + auto abs_lt = [](const double lhs, const double rhs) -> bool { return std::abs(lhs) < std::abs(rhs); }; auto iter = std::max_element(upsampled.cbegin(), upsampled.cend(), abs_lt); return Lerp(onset, static_cast(std::distance(upsampled.cbegin(), iter))/(10*rate), f); diff --git a/utils/makemhr/loadsofa.cpp b/utils/makemhr/loadsofa.cpp index f2942090..903019d8 100644 --- a/utils/makemhr/loadsofa.cpp +++ b/utils/makemhr/loadsofa.cpp @@ -241,7 +241,7 @@ auto CalcHrirOnset(PPhaseResampler &rs, const uint rate, al::span upsamp { rs.process(hrir, upsampled); - auto abs_lt = [](const double &lhs, const double &rhs) -> bool + auto abs_lt = [](const double lhs, const double rhs) -> bool { return std::abs(lhs) < std::abs(rhs); }; auto iter = std::max_element(upsampled.cbegin(), upsampled.cend(), abs_lt); return static_cast(std::distance(upsampled.cbegin(), iter)) / diff --git a/utils/makemhr/makemhr.cpp b/utils/makemhr/makemhr.cpp index b9e1f203..b6bafba9 100644 --- a/utils/makemhr/makemhr.cpp +++ b/utils/makemhr/makemhr.cpp @@ -784,7 +784,7 @@ void SynthesizeHrirs(HrirDataT *hData) */ FftForward(static_cast(htemp.size()), htemp.data()); std::transform(htemp.cbegin(), htemp.cbegin()+m, filter.begin(), - [](const complex_d &c) -> double { return std::abs(c); }); + [](const complex_d c) -> double { return std::abs(c); }); for(uint ai{0u};ai < field.mEvs[ei].mAzs.size();ai++) { @@ -824,7 +824,7 @@ void SynthesizeHrirs(HrirDataT *hData) } FftForward(static_cast(htemp.size()), htemp.data()); std::transform(htemp.cbegin(), htemp.cbegin()+m, filter.begin(), - [](const complex_d &c) -> double { return std::abs(c); }); + [](const complex_d c) -> double { return std::abs(c); }); for(uint ti{0u};ti < channels;ti++) { diff --git a/utils/sofa-info.cpp b/utils/sofa-info.cpp index 56e69d20..e899c66c 100644 --- a/utils/sofa-info.cpp +++ b/utils/sofa-info.cpp @@ -105,7 +105,7 @@ void PrintCompatibleLayout(const al::span xyzs) } // Load and inspect the given SOFA file. -void SofaInfo(const std::string filename) +void SofaInfo(const std::string &filename) { int err; MySofaHrtfPtr sofa{mysofa_load(filename.c_str(), &err)}; diff --git a/utils/sofa-support.cpp b/utils/sofa-support.cpp index fff7de45..ecaaf3d6 100644 --- a/utils/sofa-support.cpp +++ b/utils/sofa-support.cpp @@ -47,7 +47,7 @@ using double3 = std::array; * equality of unique elements. */ std::vector GetUniquelySortedElems(const std::vector &aers, const uint axis, - const std::array filters, const std::array epsilons) + const std::array &filters, const std::array &epsilons) { std::vector elems; for(const double3 &aer : aers) diff --git a/utils/uhjdecoder.cpp b/utils/uhjdecoder.cpp index c292dfb0..7bedcb22 100644 --- a/utils/uhjdecoder.cpp +++ b/utils/uhjdecoder.cpp @@ -92,10 +92,9 @@ void fwrite32le(uint val, FILE *f) fwrite(data.data(), 1, data.size(), f); } -byte4 f32AsLEBytes(const float &value) +byte4 f32AsLEBytes(const float value) { - byte4 ret{}; - std::memcpy(ret.data(), &value, 4); + auto ret = al::bit_cast(value); if constexpr(al::endian::native == al::endian::big) { std::swap(ret[0], ret[3]); diff --git a/utils/uhjencoder.cpp b/utils/uhjencoder.cpp index e02ed486..f0d14d0c 100644 --- a/utils/uhjencoder.cpp +++ b/utils/uhjencoder.cpp @@ -482,7 +482,7 @@ int main(al::span args) continue; const auto spkr = std::find_if(spkrs.cbegin(), spkrs.cend(), - [chanid](const SpeakerPos &pos){return pos.mChannelID == chanid;}); + [chanid](const SpeakerPos pos){return pos.mChannelID == chanid;}); if(spkr == spkrs.cend()) { fprintf(stderr, " ... failed to find channel ID %d\n", chanid); -- 2.11.4.GIT