Skip to content

Commit 7dbd3c4

Browse files
committed
remove some stringstreams
Looks like they're slow under Cygwin. Signed-off-by: Rosen Penev <rosenp@gmail.com>
1 parent 41a8a4b commit 7dbd3c4

19 files changed

+192
-450
lines changed

samples/iptctest.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ void processAdd(const std::string& line, int num, IptcData& iptcData) {
8686

8787
std::string data(line.substr(dataStart));
8888
// if data starts and ends with quotes, remove them
89-
if (data.front() == '\"' && data.back() == '\"') {
89+
if (data.front() == '"' && data.back() == '"') {
9090
data = data.substr(1, data.size() - 2);
9191
}
9292
TypeId type = IptcDataSets::dataSetType(iptcKey.tag(), iptcKey.record());
@@ -133,7 +133,7 @@ void processModify(const std::string& line, int num, IptcData& iptcData) {
133133

134134
std::string data(line.substr(dataStart));
135135
// if data starts and ends with quotes, remove them
136-
if (data.front() == '\"' && data.back() == '\"') {
136+
if (data.front() == '"' && data.back() == '"') {
137137
data = data.substr(1, data.size() - 2);
138138
}
139139
TypeId type = IptcDataSets::dataSetType(iptcKey.tag(), iptcKey.record());

src/canonmn_int.cpp

Lines changed: 20 additions & 95 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include "error.hpp"
1212
#include "exif.hpp"
1313
#include "i18n.h" // NLS support.
14+
#include "image_int.hpp"
1415
#include "makernote_int.hpp"
1516
#include "tags_int.hpp"
1617
#include "types.hpp"
@@ -2760,11 +2761,8 @@ const TagInfo* CanonMakerNote::tagListTi() {
27602761
}
27612762

27622763
std::ostream& CanonMakerNote::printFiFileNumber(std::ostream& os, const Value& value, const ExifData* metadata) {
2763-
std::ios::fmtflags f(os.flags());
27642764
if (!metadata || value.typeId() != unsignedLong || value.count() == 0) {
2765-
os << "(" << value << ")";
2766-
os.flags(f);
2767-
return os;
2765+
return os << "(" << value << ")";
27682766
}
27692767

27702768
auto pos = metadata->findKey(ExifKey("Exif.Image.Model"));
@@ -2776,32 +2774,22 @@ std::ostream& CanonMakerNote::printFiFileNumber(std::ostream& os, const Value& v
27762774
if (Internal::contains(model, "20D") || Internal::contains(model, "350D") ||
27772775
model.substr(model.size() - 8, 8) == "REBEL XT" || Internal::contains(model, "Kiss Digital N")) {
27782776
uint32_t val = value.toUint32();
2779-
uint32_t dn = (val & 0xffc0) >> 6;
2780-
uint32_t fn = ((val >> 16) & 0xff) + ((val & 0x3f) << 8);
2781-
os << std::dec << dn << "-" << std::setw(4) << std::setfill('0') << fn;
2782-
os.flags(f);
2783-
return os;
2777+
return os << stringFormat("{}-{:04}", (val & 0xffc0) >> 6, ((val >> 16) & 0xff) + ((val & 0x3f) << 8));
27842778
}
27852779
if (Internal::contains(model, "30D") || Internal::contains(model, "400D") || Internal::contains(model, "REBEL XTi") ||
27862780
Internal::contains(model, "Kiss Digital X") || Internal::contains(model, "K236")) {
27872781
uint32_t val = value.toUint32();
27882782
uint32_t dn = (val & 0xffc00) >> 10;
27892783
while (dn < 100)
27902784
dn += 0x40;
2791-
uint32_t fn = ((val & 0x3ff) << 4) + ((val >> 20) & 0x0f);
2792-
os << std::dec << dn << "-" << std::setw(4) << std::setfill('0') << fn;
2793-
os.flags(f);
2794-
return os;
2785+
return os << stringFormat("{}-{:04}", dn, ((val & 0x3ff) << 4) + ((val >> 20) & 0x0f));
27952786
}
27962787

2797-
os.flags(f);
27982788
return os << "(" << value << ")";
27992789
}
28002790

28012791
std::ostream& CanonMakerNote::printFocalLength(std::ostream& os, const Value& value, const ExifData* metadata) {
2802-
std::ios::fmtflags f(os.flags());
28032792
if (!metadata || value.count() < 4 || value.typeId() != unsignedShort) {
2804-
os.flags(f);
28052793
return os << value;
28062794
}
28072795

@@ -2810,18 +2798,10 @@ std::ostream& CanonMakerNote::printFocalLength(std::ostream& os, const Value& va
28102798
if (pos != metadata->end() && pos->value().count() >= 3 && pos->value().typeId() == unsignedShort) {
28112799
float fu = pos->value().toFloat(2);
28122800
if (fu != 0.0F) {
2813-
float fl = value.toFloat(1) / fu;
2814-
std::ostringstream oss;
2815-
oss.copyfmt(os);
2816-
os << std::fixed << std::setprecision(1);
2817-
os << fl << " mm";
2818-
os.copyfmt(oss);
2819-
os.flags(f);
2820-
return os;
2801+
return os << stringFormat("{:.1f} mm", value.toFloat(1) / fu);
28212802
}
28222803
}
28232804

2824-
os.flags(f);
28252805
return os << value;
28262806
}
28272807

@@ -2833,16 +2813,11 @@ std::ostream& CanonMakerNote::print0x0008(std::ostream& os, const Value& value,
28332813
}
28342814

28352815
std::ostream& CanonMakerNote::print0x000a(std::ostream& os, const Value& value, const ExifData*) {
2836-
std::istringstream is(value.toString());
2837-
uint32_t l = 0;
2838-
is >> l;
2839-
return os << std::setw(4) << std::setfill('0') << std::hex << ((l & 0xffff0000) >> 16) << std::setw(5)
2840-
<< std::setfill('0') << std::dec << (l & 0x0000ffff);
2816+
uint32_t l = std::stoul(value.toString());
2817+
return os << stringFormat("{:04x}{:05}", (l >> 16) & 0xFFFF, l & 0xFFFF);
28412818
}
28422819

28432820
std::ostream& CanonMakerNote::print0x000c(std::ostream& os, const Value& value, const ExifData* exifData) {
2844-
std::istringstream is(value.toString());
2845-
28462821
if (!exifData) {
28472822
return os << value;
28482823
}
@@ -2851,10 +2826,8 @@ std::ostream& CanonMakerNote::print0x000c(std::ostream& os, const Value& value,
28512826
auto pos = exifData->findKey(key);
28522827
// if model is EOS D30
28532828
if (pos != exifData->end() && pos->value().count() == 1 && pos->value().toInt64() == 0x01140000) {
2854-
uint32_t l = 0;
2855-
is >> l;
2856-
return os << std::setw(4) << std::setfill('0') << std::hex << ((l & 0xffff0000) >> 16) << std::setw(5)
2857-
<< std::setfill('0') << std::dec << (l & 0x0000ffff);
2829+
uint32_t l = std::stoul(value.toString());
2830+
return os << stringFormat("{:04x}{:05}", (l >> 16) & 0xFFFF, l & 0xFFFF);
28582831
}
28592832
return os << value;
28602833
}
@@ -3028,62 +3001,42 @@ std::ostream& CanonMakerNote::printCsLensType(std::ostream& os, const Value& val
30283001
}
30293002

30303003
std::ostream& CanonMakerNote::printCsLens(std::ostream& os, const Value& value, const ExifData*) {
3031-
std::ios::fmtflags f(os.flags());
3032-
30333004
if (value.count() < 3 || value.typeId() != unsignedShort) {
3034-
os << "(" << value << ")";
3035-
os.flags(f);
3036-
return os;
3005+
return os << "(" << value << ")";
30373006
}
30383007

30393008
float fu = value.toFloat(2);
30403009
if (fu == 0.0F)
30413010
return os << value;
30423011
float len1 = value.toInt64(0) / fu;
30433012
float len2 = value.toInt64(1) / fu;
3044-
std::ostringstream oss;
3045-
oss.copyfmt(os);
3046-
os << std::fixed << std::setprecision(1);
30473013
if (len1 == len2) {
3048-
os << len1 << " mm";
3049-
} else {
3050-
os << len2 << " - " << len1 << " mm";
3014+
return os << stringFormat("{:.1f} mm", len1);
30513015
}
3052-
os.copyfmt(oss);
3053-
os.flags(f);
3054-
return os;
3016+
return os << stringFormat("{:.1f} - {:.1f} mm", len2, len1);
30553017
}
30563018

30573019
std::ostream& CanonMakerNote::printLe0x0000(std::ostream& os, const Value& value, const ExifData*) {
30583020
if (value.typeId() != unsignedByte || value.size() != 5)
30593021
return os << "(" << value << ")";
3060-
std::ios::fmtflags f(os.flags());
3061-
std::ostringstream oss;
3062-
oss.copyfmt(os);
30633022
for (size_t i = 0; i < value.size(); ++i) {
3064-
os << std::setw(2) << std::setfill('0') << std::hex << value.toInt64(i);
3023+
os << stringFormat("{:02x}", value.toInt64(i));
30653024
}
3066-
os.copyfmt(oss);
3067-
os.flags(f);
30683025
return os;
30693026
}
30703027

30713028
std::ostream& CanonMakerNote::printSi0x0001(std::ostream& os, const Value& value, const ExifData*) {
3072-
std::ios::fmtflags f(os.flags());
30733029
if (value.typeId() == unsignedShort && value.count() > 0) {
30743030
os << std::pow(2.0F, canonEv(value.toInt64()) / 32) * 100.0F;
30753031
}
3076-
os.flags(f);
30773032
return os;
30783033
}
30793034

30803035
std::ostream& CanonMakerNote::printSi0x0002(std::ostream& os, const Value& value, const ExifData*) {
3081-
std::ios::fmtflags f(os.flags());
30823036
if (value.typeId() == unsignedShort && value.count() > 0) {
30833037
// Ported from Exiftool by Will Stokes
30843038
os << std::pow(2.0F, canonEv(value.toInt64())) * 100.0F / 32.0F;
30853039
}
3086-
os.flags(f);
30873040
return os;
30883041
}
30893042

@@ -3093,11 +3046,8 @@ std::ostream& CanonMakerNote::printSi0x0003(std::ostream& os, const Value& value
30933046
// It might be explained by the fact, that most Canons have a longest
30943047
// exposure of 30s which is 5 EV below 1s
30953048
// see also printSi0x0017
3096-
std::ostringstream oss;
3097-
oss.copyfmt(os);
30983049
auto res = std::lround(100.0 * (static_cast<short>(value.toInt64()) / 32.0 + 5.0));
3099-
os << std::fixed << std::setprecision(2) << res / 100.0;
3100-
os.copyfmt(oss);
3050+
os << stringFormat("{:.2f}", res / 100.0);
31013051
}
31023052
return os;
31033053
}
@@ -3143,35 +3093,26 @@ std::ostream& CanonMakerNote::printSi0x000e(std::ostream& os, const Value& value
31433093
}
31443094

31453095
std::ostream& CanonMakerNote::printSi0x0013(std::ostream& os, const Value& value, const ExifData*) {
3146-
std::ios::fmtflags f(os.flags());
31473096
if (value.typeId() != unsignedShort || value.count() == 0)
31483097
return os << value;
31493098

31503099
if (auto l = value.toInt64(); l == 0xffff) {
3151-
os << "Infinite";
3152-
} else {
3153-
os << value.toInt64() / 100.0 << " m";
3100+
return os << "Infinite";
31543101
}
3155-
os.flags(f);
3156-
return os;
3102+
return os << value.toInt64() / 100.0 << " m";
31573103
}
31583104

31593105
std::ostream& CanonMakerNote::printSi0x0015(std::ostream& os, const Value& value, const ExifData*) {
31603106
if (value.typeId() != unsignedShort || value.count() == 0)
31613107
return os << value;
31623108

3163-
std::ostringstream oss;
3164-
oss.copyfmt(os);
31653109
const auto val = static_cast<int16_t>(value.toInt64());
31663110
if (val < 0)
31673111
return os << value;
3168-
os << std::setprecision(2) << "F" << fnumber(canonEv(val));
3169-
os.copyfmt(oss);
3170-
return os;
3112+
return os << stringFormat("F{:.2}", fnumber(canonEv(val)));
31713113
}
31723114

31733115
std::ostream& CanonMakerNote::printSi0x0016(std::ostream& os, const Value& value, const ExifData*) {
3174-
std::ios::fmtflags f(os.flags());
31753116
if (value.typeId() != unsignedShort || value.count() == 0)
31763117
return os << value;
31773118

@@ -3180,43 +3121,27 @@ std::ostream& CanonMakerNote::printSi0x0016(std::ostream& os, const Value& value
31803121
if (r > 1) {
31813122
os << "/" << r;
31823123
}
3183-
os.flags(f);
31843124
return os << " s";
31853125
}
31863126

31873127
std::ostream& CanonMakerNote::printSi0x0017(std::ostream& os, const Value& value, const ExifData*) {
31883128
if (value.typeId() != unsignedShort || value.count() == 0)
31893129
return os << value;
3190-
3191-
std::ostringstream oss;
3192-
oss.copyfmt(os);
3193-
os << std::fixed << std::setprecision(2) << (value.toInt64() / 8.0) - 6.0;
3194-
os.copyfmt(oss);
3195-
return os;
3130+
return os << stringFormat("{:.2f}", (value.toInt64() / 8.0) - 6.0);
31963131
}
31973132

31983133
std::ostream& CanonMakerNote::printSi0x0018(std::ostream& os, const Value& value, const ExifData*) {
31993134
return os << value.toInt64() / 10;
32003135
}
32013136

32023137
std::ostream& CanonMakerNote::printFiFocusDistance(std::ostream& os, const Value& value, const ExifData*) {
3203-
std::ios::fmtflags f(os.flags());
32043138
if (value.typeId() != signedShort || value.count() == 0)
32053139
return os << value;
32063140

3207-
std::ostringstream oss;
3208-
oss.copyfmt(os);
3209-
os << std::fixed << std::setprecision(2);
3210-
32113141
if (auto l = value.toInt64(); l == -1) {
3212-
os << "Infinite";
3213-
} else {
3214-
os << value.toInt64() / 100.0 << " m";
3142+
return os << "Infinite";
32153143
}
3216-
3217-
os.copyfmt(oss);
3218-
os.flags(f);
3219-
return os;
3144+
return os << stringFormat("{:.2f} m", value.toInt64() / 100.0);
32203145
}
32213146

32223147
// *****************************************************************************

src/casiomn_int.cpp

Lines changed: 4 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
// included header files
88
#include "casiomn_int.hpp"
99
#include "i18n.h" // NLS support.
10+
#include "image_int.hpp"
1011
#include "tags.hpp"
1112
#include "tags_int.hpp"
1213
#include "types.hpp"
@@ -151,13 +152,7 @@ const TagInfo* CasioMakerNote::tagList() {
151152
}
152153

153154
std::ostream& CasioMakerNote::print0x0006(std::ostream& os, const Value& value, const ExifData*) {
154-
std::ios::fmtflags f(os.flags());
155-
std::ostringstream oss;
156-
oss.copyfmt(os);
157-
os << std::fixed << std::setprecision(2) << value.toInt64() / 1000.0 << _(" m");
158-
os.copyfmt(oss);
159-
os.flags(f);
160-
return os;
155+
return os << stringFormat("{:.2f} m", value.toInt64() / 1000.0);
161156
}
162157

163158
std::ostream& CasioMakerNote::print0x0015(std::ostream& os, const Value& value, const ExifData*) {
@@ -488,18 +483,10 @@ std::ostream& Casio2MakerNote::print0x2001(std::ostream& os, const Value& value,
488483
}
489484

490485
std::ostream& Casio2MakerNote::print0x2022(std::ostream& os, const Value& value, const ExifData*) {
491-
std::ios::fmtflags f(os.flags());
492486
if (value.toInt64() >= 0x20000000) {
493-
os << N_("Inf");
494-
os.flags(f);
495-
return os;
487+
return os << N_("Inf");
496488
}
497-
std::ostringstream oss;
498-
oss.copyfmt(os);
499-
os << std::fixed << std::setprecision(2) << value.toInt64() / 1000.0 << _(" m");
500-
os.copyfmt(oss);
501-
os.flags(f);
502-
return os;
489+
return os << stringFormat("{:.2f} m", value.toInt64() / 1000.0);
503490
}
504491

505492
} // namespace Exiv2::Internal

0 commit comments

Comments
 (0)