Skip to content

Commit 774912e

Browse files
committed
optimize istringstream slightly
Signed-off-by: Rosen Penev <rosenp@gmail.com>
1 parent c089ad8 commit 774912e

File tree

2 files changed

+7
-11
lines changed

2 files changed

+7
-11
lines changed

include/exiv2/value.hpp

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1511,14 +1511,12 @@ int ValueType<T>::read(const byte* buf, size_t len, ByteOrder byteOrder) {
15111511
template <typename T>
15121512
int ValueType<T>::read(const std::string& buf) {
15131513
std::istringstream is(buf);
1514-
T tmp = T();
1514+
T tmp;
15151515
ValueList val;
1516-
while (!(is.eof())) {
1517-
is >> tmp;
1518-
if (is.fail())
1519-
return 1;
1516+
while (is >> tmp)
15201517
val.push_back(tmp);
1521-
}
1518+
if (is.fail() && !is.eof())
1519+
return 1;
15221520
value_.swap(val);
15231521
return 0;
15241522
}

src/value.cpp

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -111,12 +111,10 @@ int DataValue::read(const std::string& buf) {
111111
std::istringstream is(buf);
112112
int tmp = 0;
113113
ValueType val;
114-
while (!(is.eof())) {
115-
is >> tmp;
116-
if (is.fail())
117-
return 1;
114+
while (is >> tmp)
118115
val.push_back(static_cast<byte>(tmp));
119-
}
116+
if (is.fail() && !is.eof())
117+
return 1;
120118
value_.swap(val);
121119
return 0;
122120
}

0 commit comments

Comments
 (0)