Skip to content

Commit 48d2e10

Browse files
beevvybaylesj
andauthored
Opportunistically take advantage of C++20 move-in/out-of stringstream (#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 <bayles.jordan@gmail.com>
1 parent 2072e2b commit 48d2e10

File tree

2 files changed

+4
-6
lines changed

2 files changed

+4
-6
lines changed

src/lib_json/json_reader.cpp

+3-5
Original file line numberDiff line numberDiff line change
@@ -587,8 +587,7 @@ bool Reader::decodeDouble(Token& token) {
587587

588588
bool Reader::decodeDouble(Token& token, Value& decoded) {
589589
double value = 0;
590-
String buffer(token.start_, token.end_);
591-
IStringStream is(buffer);
590+
IStringStream is(String(token.start_, token.end_));
592591
if (!(is >> value)) {
593592
if (value == std::numeric_limits<double>::max())
594593
value = std::numeric_limits<double>::infinity();
@@ -1622,8 +1621,7 @@ bool OurReader::decodeDouble(Token& token) {
16221621

16231622
bool OurReader::decodeDouble(Token& token, Value& decoded) {
16241623
double value = 0;
1625-
const String buffer(token.start_, token.end_);
1626-
IStringStream is(buffer);
1624+
IStringStream is(String(token.start_, token.end_));
16271625
if (!(is >> value)) {
16281626
if (value == std::numeric_limits<double>::max())
16291627
value = std::numeric_limits<double>::infinity();
@@ -1981,7 +1979,7 @@ bool parseFromStream(CharReader::Factory const& fact, IStream& sin, Value* root,
19811979
String* errs) {
19821980
OStringStream ssin;
19831981
ssin << sin.rdbuf();
1984-
String doc = ssin.str();
1982+
String doc = std::move(ssin).str();
19851983
char const* begin = doc.data();
19861984
char const* end = begin + doc.size();
19871985
// Note that we do not actually need a null-terminator.

src/lib_json/json_writer.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -1251,7 +1251,7 @@ String writeString(StreamWriter::Factory const& factory, Value const& root) {
12511251
OStringStream sout;
12521252
StreamWriterPtr const writer(factory.newStreamWriter());
12531253
writer->write(root, &sout);
1254-
return sout.str();
1254+
return std::move(sout).str();
12551255
}
12561256

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

0 commit comments

Comments
 (0)