Skip to content

Commit 081b0e5

Browse files
committed
refactor: Make const refs vars where applicable
This avoids initializing variables with the copy-constructor of a non-trivially copyable type.
1 parent 7f79746 commit 081b0e5

27 files changed

+39
-39
lines changed

src/bitcoin-cli.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -911,7 +911,7 @@ static void GetWalletBalances(UniValue& result)
911911

912912
UniValue balances(UniValue::VOBJ);
913913
for (const UniValue& wallet : wallets.getValues()) {
914-
const std::string wallet_name = wallet.get_str();
914+
const std::string& wallet_name = wallet.get_str();
915915
const UniValue getbalances = ConnectAndCallRPC(&rh, "getbalances", /* args=*/{}, wallet_name);
916916
const UniValue& balance = find_value(getbalances, "result")["mine"]["trusted"];
917917
balances.pushKV(wallet_name, balance);

src/bitcoin-tx.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -596,7 +596,7 @@ static void MutateTxSign(CMutableTransaction& tx, const std::string& flagStr)
596596
UniValue prevtxsObj = registers["prevtxs"];
597597
{
598598
for (unsigned int previdx = 0; previdx < prevtxsObj.size(); previdx++) {
599-
UniValue prevOut = prevtxsObj[previdx];
599+
const UniValue& prevOut = prevtxsObj[previdx];
600600
if (!prevOut.isObject())
601601
throw std::runtime_error("expected prevtxs internal object");
602602

src/blockfilter.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ const std::set<BlockFilterType>& AllBlockFilterTypes()
169169

170170
static std::once_flag flag;
171171
std::call_once(flag, []() {
172-
for (auto entry : g_filter_types) {
172+
for (const auto& entry : g_filter_types) {
173173
types.insert(entry.first);
174174
}
175175
});
@@ -185,7 +185,7 @@ const std::string& ListBlockFilterTypes()
185185
std::call_once(flag, []() {
186186
std::stringstream ret;
187187
bool first = true;
188-
for (auto entry : g_filter_types) {
188+
for (const auto& entry : g_filter_types) {
189189
if (!first) ret << ", ";
190190
ret << entry.second;
191191
first = false;

src/coins.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,7 @@ bool CCoinsViewErrorCatcher::GetCoin(const COutPoint &outpoint, Coin &coin) cons
296296
try {
297297
return CCoinsViewBacked::GetCoin(outpoint, coin);
298298
} catch(const std::runtime_error& e) {
299-
for (auto f : m_err_callbacks) {
299+
for (const auto& f : m_err_callbacks) {
300300
f();
301301
}
302302
LogPrintf("Error reading from database: %s\n", e.what());

src/core_read.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,7 @@ int ParseSighashString(const UniValue& sighash)
265265
{std::string("SINGLE"), int(SIGHASH_SINGLE)},
266266
{std::string("SINGLE|ANYONECANPAY"), int(SIGHASH_SINGLE|SIGHASH_ANYONECANPAY)},
267267
};
268-
std::string strHashType = sighash.get_str();
268+
const std::string& strHashType = sighash.get_str();
269269
const auto& it = map_sighash_values.find(strHashType);
270270
if (it != map_sighash_values.end()) {
271271
hash_type = it->second;

src/external_signer.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ bool ExternalSigner::Enumerate(const std::string& command, std::vector<ExternalS
2828
if (!result.isArray()) {
2929
throw std::runtime_error(strprintf("'%s' received invalid response, expected array of signers", command));
3030
}
31-
for (UniValue signer : result.getValues()) {
31+
for (const UniValue& signer : result.getValues()) {
3232
// Check for error
3333
const UniValue& error = find_value(signer, "error");
3434
if (!error.isNull()) {

src/init.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1083,7 +1083,7 @@ bool AppInitParameterInteraction(const ArgsManager& args, bool use_syscall_sandb
10831083
static bool LockDataDirectory(bool probeOnly)
10841084
{
10851085
// Make sure only a single Bitcoin process is using the data directory.
1086-
fs::path datadir = gArgs.GetDataDirNet();
1086+
const fs::path& datadir = gArgs.GetDataDirNet();
10871087
if (!DirIsWritable(datadir)) {
10881088
return InitError(strprintf(_("Cannot write to data directory '%s'; check permissions."), fs::PathToString(datadir)));
10891089
}

src/logging.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -364,7 +364,7 @@ void BCLog::Logger::LogPrintStr(const std::string& str, const std::string& loggi
364364
}
365365

366366
if (m_log_threadnames && m_started_new_line) {
367-
const auto threadname = util::ThreadGetInternalName();
367+
const auto& threadname = util::ThreadGetInternalName();
368368
str_prefixed.insert(0, "[" + (threadname.empty() ? "unknown" : threadname) + "] ");
369369
}
370370

src/netbase.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -387,7 +387,7 @@ bool Socks5(const std::string& strDest, uint16_t port, const ProxyCredentials* a
387387
return error("Error sending to proxy");
388388
}
389389
uint8_t pchRet1[2];
390-
if ((recvr = InterruptibleRecv(pchRet1, 2, g_socks5_recv_timeout, sock)) != IntrRecvError::OK) {
390+
if (InterruptibleRecv(pchRet1, 2, g_socks5_recv_timeout, sock) != IntrRecvError::OK) {
391391
LogPrintf("Socks5() connect to %s:%d failed: InterruptibleRecv() timeout or other failure\n", strDest, port);
392392
return false;
393393
}
@@ -410,7 +410,7 @@ bool Socks5(const std::string& strDest, uint16_t port, const ProxyCredentials* a
410410
}
411411
LogPrint(BCLog::PROXY, "SOCKS5 sending proxy authentication %s:%s\n", auth->username, auth->password);
412412
uint8_t pchRetA[2];
413-
if ((recvr = InterruptibleRecv(pchRetA, 2, g_socks5_recv_timeout, sock)) != IntrRecvError::OK) {
413+
if (InterruptibleRecv(pchRetA, 2, g_socks5_recv_timeout, sock) != IntrRecvError::OK) {
414414
return error("Error reading proxy authentication response");
415415
}
416416
if (pchRetA[0] != 0x01 || pchRetA[1] != 0x00) {
@@ -476,7 +476,7 @@ bool Socks5(const std::string& strDest, uint16_t port, const ProxyCredentials* a
476476
if (recvr != IntrRecvError::OK) {
477477
return error("Error reading from proxy");
478478
}
479-
if ((recvr = InterruptibleRecv(pchRet3, 2, g_socks5_recv_timeout, sock)) != IntrRecvError::OK) {
479+
if (InterruptibleRecv(pchRet3, 2, g_socks5_recv_timeout, sock) != IntrRecvError::OK) {
480480
return error("Error reading from proxy");
481481
}
482482
LogPrint(BCLog::NET, "SOCKS5 connected %s\n", strDest);

src/node/blockstorage.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -414,7 +414,7 @@ void CleanupBlockRevFiles()
414414
// Remove the rev files immediately and insert the blk file paths into an
415415
// ordered map keyed by block file index.
416416
LogPrintf("Removing unusable blk?????.dat and rev?????.dat files for -reindex with -prune\n");
417-
fs::path blocksdir = gArgs.GetBlocksDirPath();
417+
const fs::path& blocksdir = gArgs.GetBlocksDirPath();
418418
for (fs::directory_iterator it(blocksdir); it != fs::directory_iterator(); it++) {
419419
const std::string path = fs::PathToString(it->path().filename());
420420
if (fs::is_regular_file(*it) &&

0 commit comments

Comments
 (0)