From 5bfeeb70c6a7ed6ccda0576dc39050eb4240434f Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Mon, 20 Mar 2023 19:32:26 +0000 Subject: Lazy initialisation of SelectionPtr in persistValue Always needed for write phase, but only need on read if their's a name match. --- lib/persistence.cpp | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) (limited to 'lib/persistence.cpp') diff --git a/lib/persistence.cpp b/lib/persistence.cpp index 06e40c7..e22d74d 100644 --- a/lib/persistence.cpp +++ b/lib/persistence.cpp @@ -48,10 +48,15 @@ namespace Persistence { PersistenceSelect::PersistenceSelect(const std::string & n) : name {n} { } - PersistenceStore::NameAction - PersistenceSelect::setName(const std::string_view key, const Selection &) + PersistenceStore::NameActionSelection + PersistenceSelect::setName(const std::string_view key, SelectionFactory && factory) { - return (key == name) ? NameAction::Push : NameAction::Ignore; + if (key == name) { + return {NameAction::Push, factory()}; + } + else { + return {NameAction::Ignore, nullptr}; + } } void @@ -61,10 +66,11 @@ namespace Persistence { PersistenceWrite::PersistenceWrite(const Writer & o, bool sh) : out {o}, shared {sh} { } - PersistenceStore::NameAction - PersistenceWrite::setName(const std::string_view key, const Selection & s) + PersistenceStore::NameActionSelection + PersistenceWrite::setName(const std::string_view key, SelectionFactory && factory) { - if (s.needsWrite()) { + auto s = factory(); + if (s->needsWrite()) { if (!first) { out.nextValue(); } @@ -72,9 +78,9 @@ namespace Persistence { first = false; } out.pushKey(key); - return NameAction::HandleAndContinue; + return {NameAction::HandleAndContinue, std::move(s)}; } - return NameAction::Ignore; + return {NameAction::Ignore, nullptr}; } void -- cgit v1.2.3