Skip to content

Commit d1c6e03

Browse files
committed
remove various toString calls
std::format is more efficient. Signed-off-by: Rosen Penev <[email protected]>
1 parent ab48f59 commit d1c6e03

File tree

2 files changed

+22
-23
lines changed

2 files changed

+22
-23
lines changed

src/crwimage_int.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -618,7 +618,7 @@ const CrwMapping* CrwMap::crwMapping(uint16_t crwDir, uint16_t crwTagId) {
618618

619619
void CrwMap::decode0x0805(const CiffComponent& ciffComponent, const CrwMapping* /*pCrwMapping*/, Image& image,
620620
ByteOrder /*byteOrder*/) {
621-
std::string s(reinterpret_cast<const char*>(ciffComponent.pData()));
621+
auto s = Exiv2::toString(ciffComponent.pData());
622622
image.setComment(s);
623623
} // CrwMap::decode0x0805
624624

src/quicktimevideo.cpp

Lines changed: 21 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -766,35 +766,35 @@ void QuickTimeVideo::trackApertureTagDecoder(size_t size) {
766766
io_->readOrThrow(buf.data(), 2);
767767
io_->readOrThrow(buf2.data(), 2);
768768
xmpData_["Xmp.video.CleanApertureWidth"] =
769-
Exiv2::toString(buf.read_uint16(0, bigEndian)) + "." + Exiv2::toString(buf2.read_uint16(0, bigEndian));
769+
stringFormat("{}.{}", buf.read_uint16(0, bigEndian), buf2.read_uint16(0, bigEndian));
770770
io_->readOrThrow(buf.data(), 2);
771771
io_->readOrThrow(buf2.data(), 2);
772772
xmpData_["Xmp.video.CleanApertureHeight"] =
773-
Exiv2::toString(buf.read_uint16(0, bigEndian)) + "." + Exiv2::toString(buf2.read_uint16(0, bigEndian));
773+
stringFormat("{}.{}", buf.read_uint16(0, bigEndian), buf2.read_uint16(0, bigEndian));
774774
}
775775

776776
else if (equalsQTimeTag(buf, "prof")) {
777777
io_->seek(4L, BasicIo::cur);
778778
io_->readOrThrow(buf.data(), 2);
779779
io_->readOrThrow(buf2.data(), 2);
780780
xmpData_["Xmp.video.ProductionApertureWidth"] =
781-
Exiv2::toString(buf.read_uint16(0, bigEndian)) + "." + Exiv2::toString(buf2.read_uint16(0, bigEndian));
781+
stringFormat("{}.{}", buf.read_uint16(0, bigEndian), buf2.read_uint16(0, bigEndian));
782782
io_->readOrThrow(buf.data(), 2);
783783
io_->readOrThrow(buf2.data(), 2);
784784
xmpData_["Xmp.video.ProductionApertureHeight"] =
785-
Exiv2::toString(buf.read_uint16(0, bigEndian)) + "." + Exiv2::toString(buf2.read_uint16(0, bigEndian));
785+
stringFormat("{}.{}", buf.read_uint16(0, bigEndian), buf2.read_uint16(0, bigEndian));
786786
}
787787

788788
else if (equalsQTimeTag(buf, "enof")) {
789789
io_->seek(4L, BasicIo::cur);
790790
io_->readOrThrow(buf.data(), 2);
791791
io_->readOrThrow(buf2.data(), 2);
792792
xmpData_["Xmp.video.EncodedPixelsWidth"] =
793-
Exiv2::toString(buf.read_uint16(0, bigEndian)) + "." + Exiv2::toString(buf2.read_uint16(0, bigEndian));
793+
stringFormat("{}.{}", buf.read_uint16(0, bigEndian), buf2.read_uint16(0, bigEndian));
794794
io_->readOrThrow(buf.data(), 2);
795795
io_->readOrThrow(buf2.data(), 2);
796796
xmpData_["Xmp.video.EncodedPixelsHeight"] =
797-
Exiv2::toString(buf.read_uint16(0, bigEndian)) + "." + Exiv2::toString(buf2.read_uint16(0, bigEndian));
797+
stringFormat("{}.{}", buf.read_uint16(0, bigEndian), buf2.read_uint16(0, bigEndian));
798798
}
799799
}
800800
io_->seek(cur_pos + size, BasicIo::beg);
@@ -810,11 +810,11 @@ void QuickTimeVideo::CameraTagsDecoder(size_t size) {
810810
io_->seek(cur_pos, BasicIo::beg);
811811

812812
io_->readOrThrow(buf.data(), 24);
813-
xmpData_["Xmp.video.Make"] = Exiv2::toString(buf.data());
813+
xmpData_["Xmp.video.Make"] = buf.data();
814814
io_->readOrThrow(buf.data(), 14);
815-
xmpData_["Xmp.video.Model"] = Exiv2::toString(buf.data());
815+
xmpData_["Xmp.video.Model"] = buf.data();
816816
io_->readOrThrow(buf.data(), 4);
817-
xmpData_["Xmp.video.ExposureTime"] = "1/" + Exiv2::toString(ceil(buf.read_uint32(0, littleEndian) / 10.0));
817+
xmpData_["Xmp.video.ExposureTime"] = stringFormat("1/{}", std::ceil(buf.read_uint32(0, littleEndian) / 10.0));
818818
io_->readOrThrow(buf.data(), 4);
819819
io_->readOrThrow(buf2.data(), 4);
820820
xmpData_["Xmp.video.FNumber"] =
@@ -834,7 +834,7 @@ void QuickTimeVideo::CameraTagsDecoder(size_t size) {
834834
io_->seek(95L, BasicIo::cur);
835835
io_->readOrThrow(buf.data(), 48);
836836
buf.write_uint8(48, 0);
837-
xmpData_["Xmp.video.Software"] = Exiv2::toString(buf.data());
837+
xmpData_["Xmp.video.Software"] = buf.data();
838838
io_->readOrThrow(buf.data(), 4);
839839
xmpData_["Xmp.video.ISO"] = buf.read_uint32(0, littleEndian);
840840
}
@@ -896,7 +896,7 @@ void QuickTimeVideo::userDataDecoder(size_t outer_size, size_t recursion_depth)
896896
if (tv_internal)
897897
xmpData_[_(tv->label_)] = _(tv_internal->label_);
898898
else
899-
xmpData_[_(tv->label_)] = Exiv2::toString(buf.data());
899+
xmpData_[_(tv->label_)] = buf.data();
900900
}
901901

902902
else if (tv) {
@@ -938,11 +938,11 @@ void QuickTimeVideo::NikonTagsDecoder(size_t size) {
938938
std::memset(buf.data(), 0x0, buf.size());
939939

940940
io_->readOrThrow(buf.data(), 4);
941-
xmpData_["Xmp.video.PictureControlVersion"] = Exiv2::toString(buf.data());
941+
xmpData_["Xmp.video.PictureControlVersion"] = buf.data();
942942
io_->readOrThrow(buf.data(), 20);
943-
xmpData_["Xmp.video.PictureControlName"] = Exiv2::toString(buf.data());
943+
xmpData_["Xmp.video.PictureControlName"] = buf.data();
944944
io_->readOrThrow(buf.data(), 20);
945-
xmpData_["Xmp.video.PictureControlBase"] = Exiv2::toString(buf.data());
945+
xmpData_["Xmp.video.PictureControlBase"] = buf.data();
946946
io_->readOrThrow(buf.data(), 4);
947947
std::memset(buf.data(), 0x0, buf.size());
948948

@@ -1047,14 +1047,14 @@ void QuickTimeVideo::NikonTagsDecoder(size_t size) {
10471047
}
10481048

10491049
if (td) {
1050-
xmpData_[_(td->label_)] = Exiv2::toString(buf.data());
1050+
xmpData_[_(td->label_)] = buf.data();
10511051
}
10521052
} else if (dataType == 4) {
10531053
dataLength = buf.read_uint16(0, bigEndian) * 4;
10541054
std::memset(buf.data(), 0x0, buf.size());
10551055
io_->readOrThrow(buf.data(), 4);
10561056
if (td)
1057-
xmpData_[_(td->label_)] = Exiv2::toString(buf.read_uint32(0, bigEndian));
1057+
xmpData_[_(td->label_)] = buf.read_uint32(0, bigEndian);
10581058

10591059
// Sanity check with an "unreasonably" large number
10601060
if (dataLength > 200 || dataLength < 4) {
@@ -1070,7 +1070,7 @@ void QuickTimeVideo::NikonTagsDecoder(size_t size) {
10701070
std::memset(buf.data(), 0x0, buf.size());
10711071
io_->readOrThrow(buf.data(), 2);
10721072
if (td)
1073-
xmpData_[_(td->label_)] = Exiv2::toString(buf.read_uint16(0, bigEndian));
1073+
xmpData_[_(td->label_)] = buf.read_uint16(0, bigEndian);
10741074

10751075
// Sanity check with an "unreasonably" large number
10761076
if (dataLength > 200 || dataLength < 2) {
@@ -1105,8 +1105,7 @@ void QuickTimeVideo::NikonTagsDecoder(size_t size) {
11051105
io_->readOrThrow(buf.data(), 2);
11061106
io_->readOrThrow(buf2.data(), 2);
11071107
if (td)
1108-
xmpData_[_(td->label_)] =
1109-
Exiv2::toString(buf.read_uint16(0, bigEndian)) + " " + Exiv2::toString(buf2.read_uint16(0, bigEndian));
1108+
xmpData_[_(td->label_)] = stringFormat("{}.{}", buf.read_uint16(0, bigEndian), buf2.read_uint16(0, bigEndian));
11101109

11111110
// Sanity check with an "unreasonably" large number
11121111
if (dataLength > 200 || dataLength < 4) {
@@ -1207,7 +1206,7 @@ void QuickTimeVideo::audioDescDecoder() {
12071206
if (td)
12081207
xmpData_["Xmp.audio.Compressor"] = _(td->label_);
12091208
else
1210-
xmpData_["Xmp.audio.Compressor"] = Exiv2::toString(buf.data());
1209+
xmpData_["Xmp.audio.Compressor"] = buf.data();
12111210
break;
12121211
case AudioVendorID:
12131212
td = Exiv2::find(vendorIDTags, Exiv2::toString(buf.data()));
@@ -1247,7 +1246,7 @@ void QuickTimeVideo::imageDescDecoder() {
12471246
if (td)
12481247
xmpData_["Xmp.video.Codec"] = _(td->label_);
12491248
else
1250-
xmpData_["Xmp.video.Codec"] = Exiv2::toString(buf.data());
1249+
xmpData_["Xmp.video.Codec"] = buf.data();
12511250
break;
12521251
case VendorID:
12531252
td = Exiv2::find(vendorIDTags, Exiv2::toString(buf.data()));
@@ -1271,7 +1270,7 @@ void QuickTimeVideo::imageDescDecoder() {
12711270
case CompressorName:
12721271
io_->readOrThrow(buf.data(), 32);
12731272
size -= 32;
1274-
xmpData_["Xmp.video.Compressor"] = Exiv2::toString(buf.data());
1273+
xmpData_["Xmp.video.Compressor"] = buf.data();
12751274
break;
12761275
default:
12771276
break;

0 commit comments

Comments
 (0)