diff --git a/src/tags.cpp b/src/tags.cpp index 2426c0bcfc..a0d6ebef12 100644 --- a/src/tags.cpp +++ b/src/tags.cpp @@ -76,18 +76,16 @@ bool GroupInfo::operator==(const GroupName& groupName) const { } const char* ExifTags::sectionName(const ExifKey& key) { - const TagInfo* ti = tagInfo(key.tag(), key.ifdId()); - if (!ti) - return sectionInfo[static_cast(unknownTag.sectionId_)].name_; - return sectionInfo[static_cast(ti->sectionId_)].name_; + if (auto ti = tagInfo(key.tag(), key.ifdId())) + return sectionInfo[static_cast(ti->sectionId_)].name_; + return sectionInfo[static_cast(unknownTag.sectionId_)].name_; } /// \todo not used internally. At least we should test it uint16_t ExifTags::defaultCount(const ExifKey& key) { - const TagInfo* ti = tagInfo(key.tag(), key.ifdId()); - if (!ti) - return unknownTag.count_; - return ti->count_; + if (auto ti = tagInfo(key.tag(), key.ifdId())) + return ti->count_; + return unknownTag.count_; } const char* ExifTags::ifdName(const std::string& groupName) { @@ -240,12 +238,11 @@ ExifKey::ExifKey(uint16_t tag, const std::string& groupName) : p_(std::make_uniq if (!Internal::isExifIfd(ifdId) && !Internal::isMakerIfd(ifdId)) { throw Error(ErrorCode::kerInvalidIfdId, ifdId); } - const TagInfo* ti = tagInfo(tag, ifdId); - if (!ti) { - throw Error(ErrorCode::kerInvalidIfdId, ifdId); + if (auto ti = tagInfo(tag, ifdId)) { + p_->groupName_ = groupName; + p_->makeKey(tag, ifdId, ti); } - p_->groupName_ = groupName; - p_->makeKey(tag, ifdId, ti); + throw Error(ErrorCode::kerInvalidIfdId, ifdId); } ExifKey::ExifKey(const TagInfo& ti) : p_(std::make_unique()) {