mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-05-11 20:30:27 +02:00
refactor: iterate arrays via C++11 range-based for loops if idx is not needed
This commit is contained in:
parent
4c55f92c76
commit
63d4ee1968
@ -22,7 +22,6 @@ static const struct {
|
||||
{"signet", QAPP_APP_NAME_SIGNET, 35, 15},
|
||||
{"regtest", QAPP_APP_NAME_REGTEST, 160, 30},
|
||||
};
|
||||
static const unsigned network_styles_count = sizeof(network_styles)/sizeof(*network_styles);
|
||||
|
||||
// titleAddText needs to be const char* for tr()
|
||||
NetworkStyle::NetworkStyle(const QString &_appName, const int iconColorHueShift, const int iconColorSaturationReduction, const char *_titleAddText):
|
||||
@ -81,14 +80,12 @@ NetworkStyle::NetworkStyle(const QString &_appName, const int iconColorHueShift,
|
||||
const NetworkStyle* NetworkStyle::instantiate(const std::string& networkId)
|
||||
{
|
||||
std::string titleAddText = networkId == CBaseChainParams::MAIN ? "" : strprintf("[%s]", networkId);
|
||||
for (unsigned x=0; x<network_styles_count; ++x)
|
||||
{
|
||||
if (networkId == network_styles[x].networkId)
|
||||
{
|
||||
for (const auto& network_style : network_styles) {
|
||||
if (networkId == network_style.networkId) {
|
||||
return new NetworkStyle(
|
||||
network_styles[x].appName,
|
||||
network_styles[x].iconColorHueShift,
|
||||
network_styles[x].iconColorSaturationReduction,
|
||||
network_style.appName,
|
||||
network_style.iconColorHueShift,
|
||||
network_style.iconColorSaturationReduction,
|
||||
titleAddText.c_str());
|
||||
}
|
||||
}
|
||||
|
@ -23,7 +23,6 @@ static const struct {
|
||||
/* Other: linux, unix, ... */
|
||||
{"other", true, true, false}
|
||||
};
|
||||
static const unsigned platform_styles_count = sizeof(platform_styles)/sizeof(*platform_styles);
|
||||
|
||||
namespace {
|
||||
/* Local functions for colorizing single-color images */
|
||||
@ -121,15 +120,13 @@ QIcon PlatformStyle::TextColorIcon(const QIcon& icon) const
|
||||
|
||||
const PlatformStyle *PlatformStyle::instantiate(const QString &platformId)
|
||||
{
|
||||
for (unsigned x=0; x<platform_styles_count; ++x)
|
||||
{
|
||||
if (platformId == platform_styles[x].platformId)
|
||||
{
|
||||
for (const auto& platform_style : platform_styles) {
|
||||
if (platformId == platform_style.platformId) {
|
||||
return new PlatformStyle(
|
||||
platform_styles[x].platformId,
|
||||
platform_styles[x].imagesOnButtons,
|
||||
platform_styles[x].colorizeIcons,
|
||||
platform_styles[x].useExtraSpacing);
|
||||
platform_style.platformId,
|
||||
platform_style.imagesOnButtons,
|
||||
platform_style.colorizeIcons,
|
||||
platform_style.useExtraSpacing);
|
||||
}
|
||||
}
|
||||
return nullptr;
|
||||
|
20
src/rest.cpp
20
src/rest.cpp
@ -19,7 +19,6 @@
|
||||
#include <txmempool.h>
|
||||
#include <util/check.h>
|
||||
#include <util/ref.h>
|
||||
#include <util/strencodings.h>
|
||||
#include <validation.h>
|
||||
#include <version.h>
|
||||
|
||||
@ -117,9 +116,10 @@ static RetFormat ParseDataFormat(std::string& param, const std::string& strReq)
|
||||
param = strReq.substr(0, pos);
|
||||
const std::string suff(strReq, pos + 1);
|
||||
|
||||
for (unsigned int i = 0; i < ARRAYLEN(rf_names); i++)
|
||||
if (suff == rf_names[i].name)
|
||||
return rf_names[i].rf;
|
||||
for (const auto& rf_name : rf_names) {
|
||||
if (suff == rf_name.name)
|
||||
return rf_name.rf;
|
||||
}
|
||||
|
||||
/* If no suffix is found, return original string. */
|
||||
param = strReq;
|
||||
@ -129,12 +129,13 @@ static RetFormat ParseDataFormat(std::string& param, const std::string& strReq)
|
||||
static std::string AvailableDataFormatsString()
|
||||
{
|
||||
std::string formats;
|
||||
for (unsigned int i = 0; i < ARRAYLEN(rf_names); i++)
|
||||
if (strlen(rf_names[i].name) > 0) {
|
||||
for (const auto& rf_name : rf_names) {
|
||||
if (strlen(rf_name.name) > 0) {
|
||||
formats.append(".");
|
||||
formats.append(rf_names[i].name);
|
||||
formats.append(rf_name.name);
|
||||
formats.append(", ");
|
||||
}
|
||||
}
|
||||
|
||||
if (formats.length() > 0)
|
||||
return formats.substr(0, formats.length() - 2);
|
||||
@ -695,6 +696,7 @@ void InterruptREST()
|
||||
|
||||
void StopREST()
|
||||
{
|
||||
for (unsigned int i = 0; i < ARRAYLEN(uri_prefixes); i++)
|
||||
UnregisterHTTPHandler(uri_prefixes[i].prefix, false);
|
||||
for (const auto& up : uri_prefixes) {
|
||||
UnregisterHTTPHandler(up.prefix, false);
|
||||
}
|
||||
}
|
||||
|
@ -219,8 +219,7 @@ BOOST_AUTO_TEST_CASE(CreateNewBlock_validity)
|
||||
static_assert(sizeof(blockinfo) / sizeof(*blockinfo) == 110, "Should have 110 blocks to import");
|
||||
int baseheight = 0;
|
||||
std::vector<CTransactionRef> txFirst;
|
||||
for (unsigned int i = 0; i < sizeof(blockinfo)/sizeof(*blockinfo); ++i)
|
||||
{
|
||||
for (const auto& bi : blockinfo) {
|
||||
CBlock *pblock = &pblocktemplate->block; // pointer for convenience
|
||||
{
|
||||
LOCK(cs_main);
|
||||
@ -229,7 +228,7 @@ BOOST_AUTO_TEST_CASE(CreateNewBlock_validity)
|
||||
CMutableTransaction txCoinbase(*pblock->vtx[0]);
|
||||
txCoinbase.nVersion = 1;
|
||||
txCoinbase.vin[0].scriptSig = CScript();
|
||||
txCoinbase.vin[0].scriptSig.push_back(blockinfo[i].extranonce);
|
||||
txCoinbase.vin[0].scriptSig.push_back(bi.extranonce);
|
||||
txCoinbase.vin[0].scriptSig.push_back(::ChainActive().Height());
|
||||
txCoinbase.vout.resize(1); // Ignore the (optional) segwit commitment added by CreateNewBlock (as the hardcoded nonces don't account for this)
|
||||
txCoinbase.vout[0].scriptPubKey = CScript();
|
||||
@ -239,7 +238,7 @@ BOOST_AUTO_TEST_CASE(CreateNewBlock_validity)
|
||||
if (txFirst.size() < 4)
|
||||
txFirst.push_back(pblock->vtx[0]);
|
||||
pblock->hashMerkleRoot = BlockMerkleRoot(*pblock);
|
||||
pblock->nNonce = blockinfo[i].nonce;
|
||||
pblock->nNonce = bi.nonce;
|
||||
}
|
||||
std::shared_ptr<const CBlock> shared_pblock = std::make_shared<const CBlock>(*pblock);
|
||||
BOOST_CHECK(Assert(m_node.chainman)->ProcessNewBlock(chainparams, shared_pblock, true, nullptr));
|
||||
|
Loading…
x
Reference in New Issue
Block a user