Skip to content

Commit c997b09

Browse files
committed
algorithm conversions
Signed-off-by: Rosen Penev <[email protected]>
1 parent d789968 commit c997b09

File tree

2 files changed

+18
-22
lines changed

2 files changed

+18
-22
lines changed

src/makernote_int.cpp

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -887,10 +887,13 @@ constexpr auto nikonArrayIdx = std::array{
887887
int nikonSelector(uint16_t tag, const byte* pData, size_t size, TiffComponent* const /*pRoot*/) {
888888
if (size < 4)
889889
return -1;
890-
for (auto&& aix : nikonArrayIdx)
891-
if (aix == NikonArrayIdx::Key(tag, reinterpret_cast<const char*>(pData), size))
892-
return aix.idx_;
893-
return -1;
890+
891+
auto ix = NikonArrayIdx::Key(tag, reinterpret_cast<const char*>(pData), size);
892+
auto it = std::find_if(nikonArrayIdx.begin(), nikonArrayIdx.end(), [ix](auto&& aix) { return aix == ix; });
893+
if (it == nikonArrayIdx.end())
894+
return -1;
895+
896+
return it->idx_;
894897
}
895898

896899
DataBuf nikonCrypt(uint16_t tag, const byte* pData, size_t size, TiffComponent* const pRoot) {

src/sonymn_int.cpp

Lines changed: 11 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -855,12 +855,9 @@ std::ostream& SonyMakerNote::printSonyMisc3cShotNumberSincePowerUp(std::ostream&
855855
"DSC-RX100M4", "DSC-RX100M5", "DSC-WX220", "DSC-WX350", "DSC-WX500",
856856
};
857857

858-
std::string model = pos->toString();
859-
for (auto& m : models) {
860-
if (m == model)
861-
return os << value.toInt64();
862-
}
863-
858+
bool f = std::any_of(models.begin(), models.end(), [model = pos->toString()](auto&& m) { return m == model; });
859+
if (f)
860+
return os << value.toInt64();
864861
return os << N_("n/a");
865862
}
866863

@@ -923,13 +920,11 @@ std::ostream& SonyMakerNote::printSonyMisc3cSonyImageHeight(std::ostream& os, co
923920
if (pos == metadata->end())
924921
return os << "(" << value << ")";
925922

926-
std::string model = pos->toString();
927-
928923
// Models that do not support this tag
929-
for (auto& m : {"ILCE-1", "ILCE-7SM3", "ILME-FX3"}) {
930-
if (m == model)
931-
return os << N_("n/a");
932-
}
924+
const auto models = std::array{"ILCE-1", "ILCE-7SM3", "ILME-FX3"};
925+
bool f = std::any_of(models.begin(), models.end(), [model = pos->toString()](auto&& m) { return m == model; });
926+
if (f)
927+
return os << N_("n/a");
933928

934929
const auto val = value.toInt64();
935930
return val > 0 ? os << (8 * val) : os << N_("n/a");
@@ -944,13 +939,11 @@ std::ostream& SonyMakerNote::printSonyMisc3cModelReleaseYear(std::ostream& os, c
944939
if (pos == metadata->end())
945940
return os << "(" << value << ")";
946941

947-
std::string model = pos->toString();
948-
949942
// Models that do not support this tag
950-
for (auto& m : {"ILCE-1", "ILCE-7SM3", "ILME-FX3"}) {
951-
if (m == model)
952-
return os << N_("n/a");
953-
}
943+
const auto models = std::array{"ILCE-1", "ILCE-7SM3", "ILME-FX3"};
944+
bool f = std::any_of(models.begin(), models.end(), [model = pos->toString()](auto&& m) { return m == model; });
945+
if (f)
946+
return os << N_("n/a");
954947

955948
const auto val = value.toInt64();
956949
if (val > 99)

0 commit comments

Comments
 (0)