From 133ebfe96385a0e94ab8b029a31ca0cd7a23c50a Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Sat, 1 May 2021 19:56:59 +0100 Subject: Pass new values more efficiently --- lib/jsonParse-persistence.cpp | 4 ++-- lib/persistence.cpp | 9 ++++----- lib/persistence.h | 20 ++++++++++---------- 3 files changed, 16 insertions(+), 17 deletions(-) (limited to 'lib') diff --git a/lib/jsonParse-persistence.cpp b/lib/jsonParse-persistence.cpp index 5b3314e..7c00773 100644 --- a/lib/jsonParse-persistence.cpp +++ b/lib/jsonParse-persistence.cpp @@ -44,7 +44,7 @@ namespace Persistence { void JsonParsePersistence::pushText(std::string && value) { - pushValue(value); + pushValue(std::move(value)); } void @@ -72,7 +72,7 @@ namespace Persistence { JsonParsePersistence::pushValue(T && value) { current()->beforeValue(stk); - current()->setValue(value); + current()->setValue(std::forward(value)); stk.pop(); } diff --git a/lib/persistence.cpp b/lib/persistence.cpp index 15391ad..c4ee142 100644 --- a/lib/persistence.cpp +++ b/lib/persistence.cpp @@ -27,25 +27,24 @@ namespace Persistence { } void - Selection::setValue(float &) + Selection::setValue(float) { throw std::runtime_error("Unexpected float"); } void - Selection::setValue(bool &) + Selection::setValue(bool) { throw std::runtime_error("Unexpected bool"); } - void - Selection::setValue(const std::nullptr_t &) + void Selection::setValue(std::nullptr_t) { throw std::runtime_error("Unexpected null"); } void - Selection::setValue(std::string &) + Selection::setValue(std::string &&) { throw std::runtime_error("Unexpected string"); } diff --git a/lib/persistence.h b/lib/persistence.h index e8e3415..5d5fb0f 100644 --- a/lib/persistence.h +++ b/lib/persistence.h @@ -28,10 +28,10 @@ namespace Persistence { virtual ~Selection() = default; DEFAULT_MOVE_COPY(Selection); - virtual void setValue(float &); - virtual void setValue(bool &); - virtual void setValue(const std::nullptr_t &); - virtual void setValue(std::string &); + virtual void setValue(float); + virtual void setValue(bool); + virtual void setValue(std::nullptr_t); + virtual void setValue(std::string &&); virtual void beginArray(Stack &); virtual void beginObject(Stack &); virtual void endObject(Stack &); @@ -67,9 +67,10 @@ namespace Persistence { template struct SelectionT : public SelectionV { using SelectionV::SelectionV; + using P = std::conditional_t, T, T &&>; void - setValue(T & evalue) override + setValue(P evalue) override { std::swap(this->v, evalue); } @@ -190,7 +191,7 @@ namespace Persistence { using SelectionV::SelectionV; void - setValue(std::string & type) override + setValue(std::string && type) override { if constexpr (shared) { auto no = Persistable::callSharedFactory(type); @@ -214,7 +215,7 @@ namespace Persistence { using SelectionV::SelectionV; void - setValue(std::string & id) override + setValue(std::string && id) override { sharedObjects.emplace(id, this->v); } @@ -271,8 +272,7 @@ namespace Persistence { using SelectionV::SelectionV; - void - setValue(const std::nullptr_t &) override + void setValue(std::nullptr_t) override { this->v.reset(); } @@ -298,7 +298,7 @@ namespace Persistence { using SelectionPtrBase, true>::SelectionPtrBase; void - setValue(std::string & id) override + setValue(std::string && id) override { if (auto teo = std::dynamic_pointer_cast(sharedObjects.at(id))) { this->v = std::move(teo); -- cgit v1.2.3