Merge #13480: Avoid copies in range-for loops and add a warning to detect them
d92204c900
build: add warning to detect hidden copies in range-for loops (Cory Fields)466e16e0e8
cleanup: avoid hidden copies in range-for loops (Cory Fields) Pull request description: Following-up on #13241, which was itself a follow-up of #12169. See title. Fixing these would otherwise be a continuous process, adding the warning should keep them from cropping up. Note that the warning seems to be Clang-only for now. Tree-SHA512: ccfb769c3128b3f92c95715abcf21ee2496fe2aa384f80efead1529a28eeb56b98995b531b49a089f8142601389e63f7bb935963d724eacde4f5e1b4a024934b
This commit is contained in:
commit
31145a3d7c
7 changed files with 10 additions and 9 deletions
|
@ -301,6 +301,7 @@ if test "x$CXXFLAGS_overridden" = "xno"; then
|
|||
AX_CHECK_COMPILE_FLAG([-Wvla],[WARN_CXXFLAGS="$WARN_CXXFLAGS -Wvla"],,[[$CXXFLAG_WERROR]])
|
||||
AX_CHECK_COMPILE_FLAG([-Wformat-security],[WARN_CXXFLAGS="$WARN_CXXFLAGS -Wformat-security"],,[[$CXXFLAG_WERROR]])
|
||||
AX_CHECK_COMPILE_FLAG([-Wthread-safety-analysis],[WARN_CXXFLAGS="$WARN_CXXFLAGS -Wthread-safety-analysis"],,[[$CXXFLAG_WERROR]])
|
||||
AX_CHECK_COMPILE_FLAG([-Wrange-loop-analysis],[WARN_CXXFLAGS="$WARN_CXXFLAGS -Wrange-loop-analysis"],,[[$CXXFLAG_WERROR]])
|
||||
|
||||
## Some compilers (gcc) ignore unknown -Wno-* options, but warn about all
|
||||
## unknown options if any other warning is produced. Test the -Wfoo case, and
|
||||
|
|
|
@ -209,7 +209,7 @@ bool BlockAssembler::TestPackage(uint64_t packageSize, int64_t packageSigOpsCost
|
|||
// segwit activation)
|
||||
bool BlockAssembler::TestPackageTransactions(const CTxMemPool::setEntries& package)
|
||||
{
|
||||
for (const CTxMemPool::txiter it : package) {
|
||||
for (CTxMemPool::txiter it : package) {
|
||||
if (!IsFinalTx(it->GetTx(), nHeight, nLockTimeCutoff))
|
||||
return false;
|
||||
if (!fIncludeWitness && it->GetTx().HasWitness())
|
||||
|
@ -241,7 +241,7 @@ int BlockAssembler::UpdatePackagesForAdded(const CTxMemPool::setEntries& already
|
|||
indexed_modified_transaction_set &mapModifiedTx)
|
||||
{
|
||||
int nDescendantsUpdated = 0;
|
||||
for (const CTxMemPool::txiter it : alreadyAdded) {
|
||||
for (CTxMemPool::txiter it : alreadyAdded) {
|
||||
CTxMemPool::setEntries descendants;
|
||||
mempool.CalculateDescendants(it, descendants);
|
||||
// Insert all descendants (not yet in block) into the modified set
|
||||
|
|
|
@ -46,7 +46,7 @@ void MakeSingleColorImage(QImage& img, const QColor& colorbase)
|
|||
QIcon ColorizeIcon(const QIcon& ico, const QColor& colorbase)
|
||||
{
|
||||
QIcon new_ico;
|
||||
for (const QSize sz : ico.availableSizes())
|
||||
for (const QSize& sz : ico.availableSizes())
|
||||
{
|
||||
QImage img(ico.pixmap(sz).toImage());
|
||||
MakeSingleColorImage(img, colorbase);
|
||||
|
|
|
@ -853,7 +853,7 @@ static void ApplyStats(CCoinsStats &stats, CHashWriter& ss, const uint256& hash,
|
|||
ss << hash;
|
||||
ss << VARINT(outputs.begin()->second.nHeight * 2 + outputs.begin()->second.fCoinBase ? 1u : 0u);
|
||||
stats.nTransactions++;
|
||||
for (const auto output : outputs) {
|
||||
for (const auto& output : outputs) {
|
||||
ss << VARINT(output.first + 1);
|
||||
ss << output.second.out.scriptPubKey;
|
||||
ss << VARINT(output.second.out.nValue, VarIntMode::NONNEGATIVE_SIGNED);
|
||||
|
|
|
@ -69,12 +69,12 @@ void CTxMemPool::UpdateForDescendants(txiter updateIt, cacheMap &cachedDescendan
|
|||
setAllDescendants.insert(cit);
|
||||
stageEntries.erase(cit);
|
||||
const setEntries &setChildren = GetMemPoolChildren(cit);
|
||||
for (const txiter childEntry : setChildren) {
|
||||
for (txiter childEntry : setChildren) {
|
||||
cacheMap::iterator cacheIt = cachedDescendants.find(childEntry);
|
||||
if (cacheIt != cachedDescendants.end()) {
|
||||
// We've already calculated this one, just add the entries for this set
|
||||
// but don't traverse again.
|
||||
for (const txiter cacheEntry : cacheIt->second) {
|
||||
for (txiter cacheEntry : cacheIt->second) {
|
||||
setAllDescendants.insert(cacheEntry);
|
||||
}
|
||||
} else if (!setAllDescendants.count(childEntry)) {
|
||||
|
|
|
@ -651,7 +651,7 @@ static bool AcceptToMemoryPoolWorker(const CChainParams& chainparams, CTxMemPool
|
|||
view.SetBackend(viewMemPool);
|
||||
|
||||
// do all inputs exist?
|
||||
for (const CTxIn txin : tx.vin) {
|
||||
for (const CTxIn& txin : tx.vin) {
|
||||
if (!pcoinsTip->HaveCoinInCache(txin.prevout)) {
|
||||
coins_to_uncache.push_back(txin.prevout);
|
||||
}
|
||||
|
@ -957,7 +957,7 @@ static bool AcceptToMemoryPoolWorker(const CChainParams& chainparams, CTxMemPool
|
|||
}
|
||||
|
||||
// Remove conflicting transactions from the mempool
|
||||
for (const CTxMemPool::txiter it : allConflicting)
|
||||
for (CTxMemPool::txiter it : allConflicting)
|
||||
{
|
||||
LogPrint(BCLog::MEMPOOL, "replacing tx %s with %s for %s BTC additional fees, %d delta bytes\n",
|
||||
it->GetTx().GetHash().ToString(),
|
||||
|
|
|
@ -200,7 +200,7 @@ bool WalletInit::Verify() const
|
|||
// Keep track of each wallet absolute path to detect duplicates.
|
||||
std::set<fs::path> wallet_paths;
|
||||
|
||||
for (const auto wallet_file : wallet_files) {
|
||||
for (const auto& wallet_file : wallet_files) {
|
||||
fs::path wallet_path = fs::absolute(wallet_file, GetWalletDir());
|
||||
|
||||
if (!wallet_paths.insert(wallet_path).second) {
|
||||
|
|
Loading…
Reference in a new issue