diff options
author | Dan Goodliffe <dan@randomdan.homeip.net> | 2019-12-20 11:51:04 +0000 |
---|---|---|
committer | Dan Goodliffe <dan@randomdan.homeip.net> | 2019-12-20 12:28:27 +0000 |
commit | b28d289659c500815bae180e482298a479dc610a (patch) | |
tree | d03cae46abfa977f79c76d55f0dc96db98da3405 | |
parent | Don't convert from UTF-8 to UTF-8 unnecessarily (diff) | |
download | libjsonpp-b28d289659c500815bae180e482298a479dc610a.tar.bz2 libjsonpp-b28d289659c500815bae180e482298a479dc610a.tar.xz libjsonpp-b28d289659c500815bae180e482298a479dc610a.zip |
Move strings instead of copying them
-rw-r--r-- | libjsonpp/jsonFlexLexer.cpp | 16 | ||||
-rw-r--r-- | libjsonpp/jsonFlexLexer.h | 4 |
2 files changed, 10 insertions, 10 deletions
diff --git a/libjsonpp/jsonFlexLexer.cpp b/libjsonpp/jsonFlexLexer.cpp index 802f9e0..42aaff8 100644 --- a/libjsonpp/jsonFlexLexer.cpp +++ b/libjsonpp/jsonFlexLexer.cpp @@ -9,8 +9,8 @@ namespace json { encoding(enc != UTF8 ? std::move(enc) : std::string()) { yy_push_state(0); - acceptValues.push([&v](const auto & value) { - v = value; + acceptValues.push([&v](auto && value) { + v = std::move(value); return &v; }); } @@ -28,8 +28,8 @@ namespace json { jsonFlexLexer::BeginObject() { auto object = std::get_if<Object>(acceptValues.top()(Object())); - acceptValues.push([object,this](const auto & value) { - return &object->insert_or_assign(name, value).first->second; + acceptValues.push([object,this](auto && value) { + return &object->emplace(std::move(name), std::move(value)).first->second; }); } @@ -37,8 +37,8 @@ namespace json { jsonFlexLexer::BeginArray() { auto array = std::get_if<Array>(acceptValues.top()(Array())); - acceptValues.push([array](const auto & value) { - return &array->emplace_back(value); + acceptValues.push([array](auto && value) { + return &array->emplace_back(std::move(value)); }); } @@ -61,9 +61,9 @@ namespace json { } void - jsonFlexLexer::PushText(const std::string & value) + jsonFlexLexer::PushText(std::string && value) { - acceptValues.top()(value); + acceptValues.top()(std::move(value)); } void diff --git a/libjsonpp/jsonFlexLexer.h b/libjsonpp/jsonFlexLexer.h index 23f2562..b5ad9a3 100644 --- a/libjsonpp/jsonFlexLexer.h +++ b/libjsonpp/jsonFlexLexer.h @@ -23,7 +23,7 @@ namespace json { void PushBoolean(bool); void PushNumber(double); void PushNull(); - void PushText(const std::string &); + void PushText(std::string &&); void PushArray(); void PushObject(); @@ -32,7 +32,7 @@ namespace json { std::string buf, name, encoding; - typedef std::function<Value *(const Value &)> AcceptValue; + using AcceptValue = std::function<Value *(Value &&)>; std::stack<AcceptValue> acceptValues; }; } |