Skip to content

Commit

Permalink
Opportunistically take advantage of C++20 move-in/out-of stringstream (
Browse files Browse the repository at this point in the history
…#1457)

* Opportunistically take advantage of C++20 move-out-of stringstream

* Opportunistically take advantage of C++20 move-in/out-of stringstream

---------

Co-authored-by: Jordan Bayles <[email protected]>
  • Loading branch information
beevvy and baylesj authored Sep 10, 2024
1 parent 2072e2b commit 48d2e10
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 6 deletions.
8 changes: 3 additions & 5 deletions src/lib_json/json_reader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -587,8 +587,7 @@ bool Reader::decodeDouble(Token& token) {

bool Reader::decodeDouble(Token& token, Value& decoded) {
double value = 0;
String buffer(token.start_, token.end_);
IStringStream is(buffer);
IStringStream is(String(token.start_, token.end_));
if (!(is >> value)) {
if (value == std::numeric_limits<double>::max())
value = std::numeric_limits<double>::infinity();
Expand Down Expand Up @@ -1622,8 +1621,7 @@ bool OurReader::decodeDouble(Token& token) {

bool OurReader::decodeDouble(Token& token, Value& decoded) {
double value = 0;
const String buffer(token.start_, token.end_);
IStringStream is(buffer);
IStringStream is(String(token.start_, token.end_));
if (!(is >> value)) {
if (value == std::numeric_limits<double>::max())
value = std::numeric_limits<double>::infinity();
Expand Down Expand Up @@ -1981,7 +1979,7 @@ bool parseFromStream(CharReader::Factory const& fact, IStream& sin, Value* root,
String* errs) {
OStringStream ssin;
ssin << sin.rdbuf();
String doc = ssin.str();
String doc = std::move(ssin).str();
char const* begin = doc.data();
char const* end = begin + doc.size();
// Note that we do not actually need a null-terminator.
Expand Down
2 changes: 1 addition & 1 deletion src/lib_json/json_writer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1251,7 +1251,7 @@ String writeString(StreamWriter::Factory const& factory, Value const& root) {
OStringStream sout;
StreamWriterPtr const writer(factory.newStreamWriter());
writer->write(root, &sout);
return sout.str();
return std::move(sout).str();
}

OStream& operator<<(OStream& sout, Value const& root) {
Expand Down

0 comments on commit 48d2e10

Please sign in to comment.