From fa3f15f2dd94ae597a66037f5928fe4e90fe099d Mon Sep 17 00:00:00 2001 From: MacroFake Date: Sat, 30 Jul 2022 14:27:47 +0200 Subject: [PATCH] refactor: Avoid copies in FlatSigningProvider Merge --- src/script/descriptor.cpp | 2 +- src/script/signingprovider.cpp | 20 +++++++------------- src/script/signingprovider.h | 5 +++-- src/test/descriptor_tests.cpp | 2 +- src/wallet/rpc/spend.cpp | 2 +- src/wallet/scriptpubkeyman.cpp | 10 +++++----- 6 files changed, 18 insertions(+), 23 deletions(-) diff --git a/src/script/descriptor.cpp b/src/script/descriptor.cpp index 9bcbe1ceefb..8ace9c3136a 100644 --- a/src/script/descriptor.cpp +++ b/src/script/descriptor.cpp @@ -644,7 +644,7 @@ public: assert(outscripts.size() == 1); subscripts.emplace_back(std::move(outscripts[0])); } - out = Merge(std::move(out), std::move(subprovider)); + out.Merge(std::move(subprovider)); std::vector pubkeys; pubkeys.reserve(entries.size()); diff --git a/src/script/signingprovider.cpp b/src/script/signingprovider.cpp index c624a176286..a82a8b252a1 100644 --- a/src/script/signingprovider.cpp +++ b/src/script/signingprovider.cpp @@ -77,20 +77,14 @@ bool FlatSigningProvider::GetTaprootBuilder(const XOnlyPubKey& output_key, Tapro return LookupHelper(tr_trees, output_key, builder); } -FlatSigningProvider Merge(const FlatSigningProvider& a, const FlatSigningProvider& b) +FlatSigningProvider& FlatSigningProvider::Merge(FlatSigningProvider&& b) { - FlatSigningProvider ret; - ret.scripts = a.scripts; - ret.scripts.insert(b.scripts.begin(), b.scripts.end()); - ret.pubkeys = a.pubkeys; - ret.pubkeys.insert(b.pubkeys.begin(), b.pubkeys.end()); - ret.keys = a.keys; - ret.keys.insert(b.keys.begin(), b.keys.end()); - ret.origins = a.origins; - ret.origins.insert(b.origins.begin(), b.origins.end()); - ret.tr_trees = a.tr_trees; - ret.tr_trees.insert(b.tr_trees.begin(), b.tr_trees.end()); - return ret; + scripts.merge(b.scripts); + pubkeys.merge(b.pubkeys); + keys.merge(b.keys); + origins.merge(b.origins); + tr_trees.merge(b.tr_trees); + return *this; } void FillableSigningProvider::ImplicitlyLearnRelatedKeyScripts(const CPubKey& pubkey) diff --git a/src/script/signingprovider.h b/src/script/signingprovider.h index 792cc903f2b..2d4234ea0b4 100644 --- a/src/script/signingprovider.h +++ b/src/script/signingprovider.h @@ -6,6 +6,7 @@ #ifndef BITCOIN_SCRIPT_SIGNINGPROVIDER_H #define BITCOIN_SCRIPT_SIGNINGPROVIDER_H +#include #include #include #include