Skip to content

Commit

Permalink
optimize istringstream slightly
Browse files Browse the repository at this point in the history
Signed-off-by: Rosen Penev <[email protected]>
  • Loading branch information
neheb committed Feb 15, 2025
1 parent c089ad8 commit 774912e
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 11 deletions.
10 changes: 4 additions & 6 deletions include/exiv2/value.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1511,14 +1511,12 @@ int ValueType<T>::read(const byte* buf, size_t len, ByteOrder byteOrder) {
template <typename T>
int ValueType<T>::read(const std::string& buf) {
std::istringstream is(buf);
T tmp = T();
T tmp;
ValueList val;
while (!(is.eof())) {
is >> tmp;
if (is.fail())
return 1;
while (is >> tmp)
val.push_back(tmp);
}
if (is.fail() && !is.eof())
return 1;
value_.swap(val);
return 0;
}
Expand Down
8 changes: 3 additions & 5 deletions src/value.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,12 +111,10 @@ int DataValue::read(const std::string& buf) {
std::istringstream is(buf);
int tmp = 0;
ValueType val;
while (!(is.eof())) {
is >> tmp;
if (is.fail())
return 1;
while (is >> tmp)
val.push_back(static_cast<byte>(tmp));
}
if (is.fail() && !is.eof())
return 1;
value_.swap(val);
return 0;
}
Expand Down

0 comments on commit 774912e

Please sign in to comment.