From c997b09a81580dbe74b1e4085672510a401cec98 Mon Sep 17 00:00:00 2001 From: Rosen Penev Date: Sun, 10 Apr 2022 01:11:19 -0700 Subject: [PATCH] algorithm conversions Signed-off-by: Rosen Penev --- src/makernote_int.cpp | 11 +++++++---- src/sonymn_int.cpp | 29 +++++++++++------------------ 2 files changed, 18 insertions(+), 22 deletions(-) diff --git a/src/makernote_int.cpp b/src/makernote_int.cpp index d0da454b..b8059883 100644 --- a/src/makernote_int.cpp +++ b/src/makernote_int.cpp @@ -887,10 +887,13 @@ constexpr auto nikonArrayIdx = std::array{ int nikonSelector(uint16_t tag, const byte* pData, size_t size, TiffComponent* const /*pRoot*/) { if (size < 4) return -1; - for (auto&& aix : nikonArrayIdx) - if (aix == NikonArrayIdx::Key(tag, reinterpret_cast(pData), size)) - return aix.idx_; - return -1; + + auto ix = NikonArrayIdx::Key(tag, reinterpret_cast(pData), size); + auto it = std::find_if(nikonArrayIdx.begin(), nikonArrayIdx.end(), [ix](auto&& aix) { return aix == ix; }); + if (it == nikonArrayIdx.end()) + return -1; + + return it->idx_; } DataBuf nikonCrypt(uint16_t tag, const byte* pData, size_t size, TiffComponent* const pRoot) { diff --git a/src/sonymn_int.cpp b/src/sonymn_int.cpp index d7c3083b..b1be5749 100644 --- a/src/sonymn_int.cpp +++ b/src/sonymn_int.cpp @@ -855,12 +855,9 @@ std::ostream& SonyMakerNote::printSonyMisc3cShotNumberSincePowerUp(std::ostream& "DSC-RX100M4", "DSC-RX100M5", "DSC-WX220", "DSC-WX350", "DSC-WX500", }; - std::string model = pos->toString(); - for (auto& m : models) { - if (m == model) - return os << value.toInt64(); - } - + bool f = std::any_of(models.begin(), models.end(), [model = pos->toString()](auto&& m) { return m == model; }); + if (f) + return os << value.toInt64(); return os << N_("n/a"); } @@ -923,13 +920,11 @@ std::ostream& SonyMakerNote::printSonyMisc3cSonyImageHeight(std::ostream& os, co if (pos == metadata->end()) return os << "(" << value << ")"; - std::string model = pos->toString(); - // Models that do not support this tag - for (auto& m : {"ILCE-1", "ILCE-7SM3", "ILME-FX3"}) { - if (m == model) - return os << N_("n/a"); - } + const auto models = std::array{"ILCE-1", "ILCE-7SM3", "ILME-FX3"}; + bool f = std::any_of(models.begin(), models.end(), [model = pos->toString()](auto&& m) { return m == model; }); + if (f) + return os << N_("n/a"); const auto val = value.toInt64(); return val > 0 ? os << (8 * val) : os << N_("n/a"); @@ -944,13 +939,11 @@ std::ostream& SonyMakerNote::printSonyMisc3cModelReleaseYear(std::ostream& os, c if (pos == metadata->end()) return os << "(" << value << ")"; - std::string model = pos->toString(); - // Models that do not support this tag - for (auto& m : {"ILCE-1", "ILCE-7SM3", "ILME-FX3"}) { - if (m == model) - return os << N_("n/a"); - } + const auto models = std::array{"ILCE-1", "ILCE-7SM3", "ILME-FX3"}; + bool f = std::any_of(models.begin(), models.end(), [model = pos->toString()](auto&& m) { return m == model; }); + if (f) + return os << N_("n/a"); const auto val = value.toInt64(); if (val > 99)