Skip to content

Commit f4e8f15

Browse files
committed
convert const TagInfo returns to constexpr
Signed-off-by: Rosen Penev <[email protected]>
1 parent 8736c1b commit f4e8f15

File tree

4 files changed

+16
-23
lines changed

4 files changed

+16
-23
lines changed

src/tags.cpp

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -74,18 +74,16 @@ bool GroupInfo::operator==(const GroupName& groupName) const {
7474
}
7575

7676
const char* ExifTags::sectionName(const ExifKey& key) {
77-
const TagInfo* ti = tagInfo(key.tag(), key.ifdId());
78-
if (!ti)
79-
return sectionInfo[static_cast<int>(unknownTag.sectionId_)].name_;
80-
return sectionInfo[static_cast<int>(ti->sectionId_)].name_;
77+
if (auto ti = tagInfo(key.tag(), key.ifdId()))
78+
return sectionInfo[static_cast<int>(ti->sectionId_)].name_;
79+
return sectionInfo[static_cast<int>(unknownTag.sectionId_)].name_;
8180
}
8281

8382
/// \todo not used internally. At least we should test it
8483
uint16_t ExifTags::defaultCount(const ExifKey& key) {
85-
const TagInfo* ti = tagInfo(key.tag(), key.ifdId());
86-
if (!ti)
87-
return unknownTag.count_;
88-
return ti->count_;
84+
if (auto ti = tagInfo(key.tag(), key.ifdId()))
85+
return ti->count_;
86+
return unknownTag.count_;
8987
}
9088

9189
const char* ExifTags::ifdName(const std::string& groupName) {
@@ -236,12 +234,11 @@ ExifKey::ExifKey(uint16_t tag, const std::string& groupName) : p_(std::make_uniq
236234
if (!Internal::isExifIfd(ifdId) && !Internal::isMakerIfd(ifdId)) {
237235
throw Error(ErrorCode::kerInvalidIfdId, ifdId);
238236
}
239-
const TagInfo* ti = tagInfo(tag, ifdId);
240-
if (!ti) {
241-
throw Error(ErrorCode::kerInvalidIfdId, ifdId);
237+
if (auto ti = tagInfo(tag, ifdId)) {
238+
p_->groupName_ = groupName;
239+
p_->makeKey(tag, ifdId, ti);
242240
}
243-
p_->groupName_ = groupName;
244-
p_->makeKey(tag, ifdId, ti);
241+
throw Error(ErrorCode::kerInvalidIfdId, ifdId);
245242
}
246243

247244
ExifKey::ExifKey(const TagInfo& ti) : p_(std::make_unique<Impl>()) {

src/tags_int.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2621,7 +2621,7 @@ URational exposureTime(float shutterSpeedValue) {
26212621
}
26222622

26232623
uint16_t tagNumber(const std::string& tagName, IfdId ifdId) {
2624-
const TagInfo* ti = tagInfo(tagName, ifdId);
2624+
auto ti = tagInfo(tagName, ifdId);
26252625
if (ti && ti->tag_ != 0xffff)
26262626
return ti->tag_;
26272627
if (!isHex(tagName, 4, "0x"))

src/tiffcomposite_int.cpp

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1438,14 +1438,10 @@ static const TagInfo* findTagInfo(uint16_t tag, IfdId group) {
14381438
return Internal::gpsTagList();
14391439
return group == IfdId::exifId ? Internal::exifTagList() : nullptr;
14401440
}();
1441-
if (!tags)
1442-
return nullptr;
1443-
1444-
for (size_t idx = 0; tags[idx].tag_ != 0xffff; ++idx) {
1445-
if (tags[idx].tag_ == tag) {
1446-
return tags + idx;
1447-
}
1448-
}
1441+
if (tags)
1442+
for (size_t idx = 0; tags[idx].tag_ != 0xffff; ++idx)
1443+
if (tags[idx].tag_ == tag)
1444+
return tags + idx;
14491445
return nullptr;
14501446
}
14511447

src/tiffvisitor_int.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -393,7 +393,7 @@ void TiffDecoder::decodeCanonAFInfo(const TiffEntryBase* object) {
393393
}
394394

395395
for (const auto& [tag, size, bSigned] : records) {
396-
const TagInfo* pTags = ExifTags::tagList("Canon");
396+
auto pTags = ExifTags::tagList("Canon");
397397
if (auto pTag = findTag(pTags, tag)) {
398398
auto v = Exiv2::Value::create(bSigned ? Exiv2::signedShort : Exiv2::unsignedShort);
399399
std::string s;

0 commit comments

Comments
 (0)