Merge bitcoin/bitcoin#31650: refactor: Avoid copies by using const references or by move-construction

fa64d8424b refactor: Enforce readability-avoid-const-params-in-decls (MarcoFalke)
faf0c2d942 refactor: Avoid copies by using const references or by move-construction (MarcoFalke)

Pull request description:

  Top level `const` in declarations is problematic for many reasons:

  * It is often a typo, where one wanted to denote a const reference. For example `bool PSBTInputSignedAndVerified(const PartiallySignedTransaction psbt, ...` is missing the `&`. This will create a redundant copy of the value.
  * In constructors it prevents move construction.
  * It can incorrectly imply some data is const, like in an imaginary example `std::span<int> Shuffle(const std::span<int>);`, where the `int`s are *not* const.
  * The compiler ignores the `const` from the declaration in the implementation.
  * It isn't used consistently anyway, not even on the same line.

  Fix some issues by:

  * Using a const reference to avoid a copy, where read-only of the value is intended. This is only done for values that may be expensive to copy.
  * Using move-construction to avoid a copy
  * Applying `readability-avoid-const-params-in-decls` via clang-tidy

ACKs for top commit:
  l0rinc:
    diff reACK fa64d8424b
  hebasto:
    ACK fa64d8424b, I have reviewed the code and it looks OK.
  sedited:
    ACK fa64d8424b

Tree-SHA512: 293c000b4ebf8fdcc75259eb0283a2e4e7892c73facfb5c3182464d6cb6a868b7f4a6682d664426bf2edecd665cf839d790bef0bae43a8c3bf1ddfdd3d068d38
This commit is contained in:
merge-script committed 2026-01-19 11:44:04 +01:00
commit c57fbbe99d
56 files changed
+97 -94

No files matched your search

+1 -1
View File
@@ -70,7 +70,7 @@ public:
/* Add an address to the model.
Returns the added address on success, and an empty string otherwise.
*/
QString addRow(const QString &type, const QString &label, const QString &address, const OutputType address_type);
QString addRow(const QString& type, const QString& label, const QString& address, OutputType address_type);
/** Look up label for address in address book, if not found return empty string. */
QString labelForAddress(const QString &address) const;
+2 -2
View File
@@ -16,7 +16,7 @@ class NetworkStyle
{
public:
/** Get style associated with provided network id, or 0 if not known */
static const NetworkStyle* instantiate(const ChainType networkId);
static const NetworkStyle* instantiate(ChainType networkId);
const QString &getAppName() const { return appName; }
const QIcon &getAppIcon() const { return appIcon; }
@@ -24,7 +24,7 @@ public:
const QString &getTitleAddText() const { return titleAddText; }
private:
NetworkStyle(const QString &appName, const int iconColorHueShift, const int iconColorSaturationReduction, const char *titleAddText);
NetworkStyle(const QString& appName, int iconColorHueShift, int iconColorSaturationReduction, const char* titleAddText);
QString appName;
QIcon appIcon;
+4 -4
View File
@@ -48,7 +48,7 @@ public:
explicit RPCConsole(interfaces::Node& node, const PlatformStyle *platformStyle, QWidget *parent);
~RPCConsole();
static bool RPCParseCommandLine(interfaces::Node* node, std::string &strResult, const std::string &strCommand, bool fExecute, std::string * const pstrFilteredOut = nullptr, const QString& wallet_name = {});
static bool RPCParseCommandLine(interfaces::Node* node, std::string& strResult, const std::string& strCommand, bool fExecute, std::string* pstrFilteredOut = nullptr, const QString& wallet_name = {});
static bool RPCExecuteCommandLine(interfaces::Node& node, std::string &strResult, const std::string &strCommand, std::string * const pstrFilteredOut = nullptr, const QString& wallet_name = {}) {
return RPCParseCommandLine(&node, strResult, strCommand, true, pstrFilteredOut, wallet_name);
}
@@ -56,8 +56,8 @@ public:
void setClientModel(ClientModel *model = nullptr, int bestblock_height = 0, int64_t bestblock_date = 0, double verification_progress = 0.0);
#ifdef ENABLE_WALLET
void addWallet(WalletModel* const walletModel);
void removeWallet(WalletModel* const walletModel);
void addWallet(WalletModel* walletModel);
void removeWallet(WalletModel* walletModel);
#endif // ENABLE_WALLET
enum MessageClass {
@@ -138,7 +138,7 @@ public Q_SLOTS:
void setTabFocus(enum TabTypes tabType);
#ifdef ENABLE_WALLET
/** Set the current (ie - active) wallet */
void setCurrentWallet(WalletModel* const wallet_model);
void setCurrentWallet(WalletModel* wallet_model);
#endif // ENABLE_WALLET
private: