Skip to content

Commit ee855c0

Browse files
committed
Reduce amount of string transformations
1 parent d5742f4 commit ee855c0

File tree

1 file changed

+17
-18
lines changed

1 file changed

+17
-18
lines changed

src/pngimage.cpp

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ static bool tEXtToDataBuf(const byte* bytes, long length, DataBuf& result) {
173173
}
174174

175175
std::string::size_type findi(const std::string& str, const std::string& substr) {
176-
return upper(str).find(upper(substr));
176+
return str.find(substr);
177177
}
178178

179179
void PngImage::printStructure(std::ostream& out, PrintStructureOption option, int depth) {
@@ -189,14 +189,14 @@ void PngImage::printStructure(std::ostream& out, PrintStructureOption option, in
189189
chType[4] = 0;
190190

191191
if (option == kpsBasic || option == kpsXMP || option == kpsIccProfile || option == kpsRecursive) {
192-
constexpr auto xmpKey = "XML:com.adobe.xmp";
193-
constexpr auto exifKey = "Raw profile type exif";
194-
constexpr auto app1Key = "Raw profile type APP1";
195-
constexpr auto iptcKey = "Raw profile type iptc";
196-
constexpr auto iccKey = "icc";
197-
constexpr auto softKey = "Software";
198-
constexpr auto commKey = "Comment";
199-
constexpr auto descKey = "Description";
192+
const auto xmpKey = upper("XML:com.adobe.xmp");
193+
const auto exifKey = upper("Raw profile type exif");
194+
const auto app1Key = upper("Raw profile type APP1");
195+
const auto iptcKey = upper("Raw profile type iptc");
196+
const auto iccKey = upper("icc");
197+
const auto softKey = upper("Software");
198+
const auto commKey = upper("Comment");
199+
const auto descKey = upper("Description");
200200

201201
bool bPrint = option == kpsBasic || option == kpsRecursive;
202202
if (bPrint) {
@@ -270,15 +270,14 @@ void PngImage::printStructure(std::ostream& out, PrintStructureOption option, in
270270
bool eXIf = std::strcmp(chType, "eXIf") == 0;
271271

272272
// for XMP, ICC etc: read and format data
273-
/// \todo inside findi we are transforming the dataString to uppercase. Therefore we are transforming it
274-
/// several times when we could do it just once and reuse it.
275-
bool bXMP = option == kpsXMP && findi(dataString, xmpKey) == 0;
276-
bool bICC = option == kpsIccProfile && findi(dataString, iccKey) == 0;
277-
bool bExif = option == kpsRecursive && (findi(dataString, exifKey) == 0 || findi(dataString, app1Key) == 0);
278-
bool bIptc = option == kpsRecursive && findi(dataString, iptcKey) == 0;
279-
bool bSoft = option == kpsRecursive && findi(dataString, softKey) == 0;
280-
bool bComm = option == kpsRecursive && findi(dataString, commKey) == 0;
281-
bool bDesc = option == kpsRecursive && findi(dataString, descKey) == 0;
273+
const auto dataStringU = upper(dataString);
274+
bool bXMP = option == kpsXMP && findi(dataStringU, xmpKey) == 0;
275+
bool bICC = option == kpsIccProfile && findi(dataStringU, iccKey) == 0;
276+
bool bExif = option == kpsRecursive && (findi(dataStringU, exifKey) == 0 || findi(dataStringU, app1Key) == 0);
277+
bool bIptc = option == kpsRecursive && findi(dataStringU, iptcKey) == 0;
278+
bool bSoft = option == kpsRecursive && findi(dataStringU, softKey) == 0;
279+
bool bComm = option == kpsRecursive && findi(dataStringU, commKey) == 0;
280+
bool bDesc = option == kpsRecursive && findi(dataStringU, descKey) == 0;
282281
bool bDump = bXMP || bICC || bExif || bIptc || bSoft || bComm || bDesc || eXIf;
283282

284283
if (bDump) {

0 commit comments

Comments
 (0)