refactor: Avoid copies by using const references or by move-construction

This commit is contained in:
MarcoFalke
2025-01-13 21:39:03 +01:00
parent 2d380aee43
commit faf0c2d942
10 changed files with 15 additions and 13 deletions

View File

@@ -15,14 +15,15 @@
#include <string>
#include <vector>
ExternalSigner::ExternalSigner(const std::string& command, const std::string chain, const std::string& fingerprint, const std::string name): m_command(command), m_chain(chain), m_fingerprint(fingerprint), m_name(name) {}
ExternalSigner::ExternalSigner(std::string command, std::string chain, std::string fingerprint, std::string name)
: m_command{std::move(command)}, m_chain{std::move(chain)}, m_fingerprint{std::move(fingerprint)}, m_name{std::move(name)} {}
std::string ExternalSigner::NetworkArg() const
{
return " --chain " + m_chain;
}
bool ExternalSigner::Enumerate(const std::string& command, std::vector<ExternalSigner>& signers, const std::string chain)
bool ExternalSigner::Enumerate(const std::string& command, std::vector<ExternalSigner>& signers, const std::string& chain)
{
// Call <command> enumerate
const UniValue result = RunCommandParseJSON(command + " enumerate");

View File

@@ -31,7 +31,7 @@ public:
//! @param[in] fingerprint master key fingerprint of the signer
//! @param[in] chain "main", "test", "regtest" or "signet"
//! @param[in] name device name
ExternalSigner(const std::string& command, const std::string chain, const std::string& fingerprint, const std::string name);
ExternalSigner(std::string command, std::string chain, std::string fingerprint, std::string name);
//! Master key fingerprint of the signer
std::string m_fingerprint;
@@ -44,7 +44,7 @@ public:
//! @param[in,out] signers vector to which new signers (with a unique master key fingerprint) are added
//! @param chain "main", "test", "regtest" or "signet"
//! @returns success
static bool Enumerate(const std::string& command, std::vector<ExternalSigner>& signers, const std::string chain);
static bool Enumerate(const std::string& command, std::vector<ExternalSigner>& signers, const std::string& chain);
//! Display address on the device. Calls `<command> displayaddress --desc <descriptor>`.
//! @param[in] descriptor Descriptor specifying which address to display.

View File

@@ -60,7 +60,8 @@ class Proxy
public:
Proxy() : m_is_unix_socket(false), m_tor_stream_isolation(false) {}
explicit Proxy(const CService& _proxy, bool tor_stream_isolation = false) : proxy(_proxy), m_is_unix_socket(false), m_tor_stream_isolation(tor_stream_isolation) {}
explicit Proxy(const std::string path, bool tor_stream_isolation = false) : m_unix_socket_path(path), m_is_unix_socket(true), m_tor_stream_isolation(tor_stream_isolation) {}
explicit Proxy(std::string path, bool tor_stream_isolation = false)
: m_unix_socket_path(std::move(path)), m_is_unix_socket(true), m_tor_stream_isolation(tor_stream_isolation) {}
CService proxy;
std::string m_unix_socket_path;

View File

@@ -322,7 +322,7 @@ bool PSBTInputSigned(const PSBTInput& input)
return !input.final_script_sig.empty() || !input.final_script_witness.IsNull();
}
bool PSBTInputSignedAndVerified(const PartiallySignedTransaction psbt, unsigned int input_index, const PrecomputedTransactionData* txdata)
bool PSBTInputSignedAndVerified(const PartiallySignedTransaction& psbt, unsigned int input_index, const PrecomputedTransactionData* txdata)
{
CTxOut utxo;
assert(input_index < psbt.inputs.size());

View File

@@ -1413,7 +1413,7 @@ PrecomputedTransactionData PrecomputePSBTData(const PartiallySignedTransaction&
bool PSBTInputSigned(const PSBTInput& input);
/** Checks whether a PSBTInput is already signed by doing script verification using final fields. */
bool PSBTInputSignedAndVerified(const PartiallySignedTransaction psbt, unsigned int input_index, const PrecomputedTransactionData* txdata);
bool PSBTInputSignedAndVerified(const PartiallySignedTransaction& psbt, unsigned int input_index, const PrecomputedTransactionData* txdata);
/** Signs a PSBTInput, verifying that all provided data matches what is being signed.
*

View File

@@ -52,7 +52,7 @@ BOOST_AUTO_TEST_CASE(util_datadir)
struct TestArgsManager : public ArgsManager
{
TestArgsManager() { m_network_only_args.clear(); }
void ReadConfigString(const std::string str_config)
void ReadConfigString(const std::string& str_config)
{
std::istringstream streamConfig(str_config);
{
@@ -63,7 +63,7 @@ struct TestArgsManager : public ArgsManager
std::string error;
BOOST_REQUIRE(ReadConfigStream(streamConfig, "", error));
}
void SetNetworkOnlyArg(const std::string arg)
void SetNetworkOnlyArg(const std::string& arg)
{
LOCK(cs_args);
m_network_only_args.insert(arg);

View File

@@ -124,7 +124,7 @@ void PushParentDescriptors(const CWallet& wallet, const CScript& script_pubkey,
entry.pushKV("parent_descs", std::move(parent_descs));
}
void HandleWalletError(const std::shared_ptr<CWallet> wallet, DatabaseStatus& status, bilingual_str& error)
void HandleWalletError(const std::shared_ptr<CWallet>& wallet, DatabaseStatus& status, bilingual_str& error)
{
if (!wallet) {
// Map bad format to not found, since bad format is returned when the

View File

@@ -54,7 +54,7 @@ std::string LabelFromValue(const UniValue& value);
//! Fetch parent descriptors of this scriptPubKey.
void PushParentDescriptors(const CWallet& wallet, const CScript& script_pubkey, UniValue& entry);
void HandleWalletError(const std::shared_ptr<CWallet> wallet, DatabaseStatus& status, bilingual_str& error);
void HandleWalletError(const std::shared_ptr<CWallet>& wallet, DatabaseStatus& status, bilingual_str& error);
void AppendLastProcessedBlock(UniValue& entry, const CWallet& wallet) EXCLUSIVE_LOCKS_REQUIRED(wallet.cs_wallet);
} // namespace wallet

View File

@@ -2534,7 +2534,7 @@ bool CWallet::TopUpKeyPool(unsigned int kpSize)
return res;
}
util::Result<CTxDestination> CWallet::GetNewDestination(const OutputType type, const std::string label)
util::Result<CTxDestination> CWallet::GetNewDestination(const OutputType type, const std::string& label)
{
LOCK(cs_wallet);
auto spk_man = GetScriptPubKeyMan(type, /*internal=*/false);

View File

@@ -783,7 +783,7 @@ public:
*/
void MarkDestinationsDirty(const std::set<CTxDestination>& destinations) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);
util::Result<CTxDestination> GetNewDestination(const OutputType type, const std::string label);
util::Result<CTxDestination> GetNewDestination(const OutputType type, const std::string& label);
util::Result<CTxDestination> GetNewChangeDestination(const OutputType type);
bool IsMine(const CTxDestination& dest) const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);