Skip to content

Commit 78da882

Browse files
committed
Util: Small improvements in gArgs usage
- Don't check gArgs.IsArgSet() is greater than 0 - Remove unneeded calls and local variables
1 parent 5292245 commit 78da882

File tree

3 files changed

+11
-15
lines changed

3 files changed

+11
-15
lines changed

src/httprpc.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ static bool multiUserAuthorized(std::string strUserPass)
9393
std::string strUser = strUserPass.substr(0, strUserPass.find(":"));
9494
std::string strPass = strUserPass.substr(strUserPass.find(":") + 1);
9595

96-
if (gArgs.IsArgSet("-rpcauth") > 0) {
96+
if (gArgs.IsArgSet("-rpcauth")) {
9797
//Search for multi-user login/pass "rpcauth" from config
9898
BOOST_FOREACH(std::string strRPCAuth, gArgs.GetArgs("-rpcauth"))
9999
{

src/httpserver.cpp

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -197,8 +197,7 @@ static bool InitHTTPAllowList()
197197
rpc_allow_subnets.push_back(CSubNet(localv4, 8)); // always allow IPv4 local subnet
198198
rpc_allow_subnets.push_back(CSubNet(localv6)); // always allow IPv6 localhost
199199
if (gArgs.IsArgSet("-rpcallowip")) {
200-
const std::vector<std::string>& vAllow = gArgs.GetArgs("-rpcallowip");
201-
for (std::string strAllow : vAllow) {
200+
for (const std::string& strAllow : gArgs.GetArgs("-rpcallowip")) {
202201
CSubNet subnet;
203202
LookupSubNet(strAllow.c_str(), subnet);
204203
if (!subnet.IsValid()) {
@@ -322,11 +321,10 @@ static bool HTTPBindAddresses(struct evhttp* http)
322321
LogPrintf("WARNING: option -rpcbind was ignored because -rpcallowip was not specified, refusing to allow everyone to connect\n");
323322
}
324323
} else if (gArgs.IsArgSet("-rpcbind")) { // Specific bind address
325-
const std::vector<std::string>& vbind = gArgs.GetArgs("-rpcbind");
326-
for (std::vector<std::string>::const_iterator i = vbind.begin(); i != vbind.end(); ++i) {
324+
for (const std::string& strRPCBind : gArgs.GetArgs("-rpcbind")) {
327325
int port = defaultPort;
328326
std::string host;
329-
SplitHostPort(*i, port, host);
327+
SplitHostPort(strRPCBind, port, host);
330328
endpoints.push_back(std::make_pair(host, port));
331329
}
332330
} else { // No specific bind address specified, bind to any

src/init.cpp

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -741,7 +741,7 @@ void InitParameterInteraction()
741741
LogPrintf("%s: parameter interaction: -whitebind set -> setting -listen=1\n", __func__);
742742
}
743743

744-
if (gArgs.IsArgSet("-connect") && gArgs.GetArgs("-connect").size() > 0) {
744+
if (gArgs.IsArgSet("-connect")) {
745745
// when only connecting to trusted nodes, do not seed via DNS, or listen by default
746746
if (SoftSetBoolArg("-dnsseed", false))
747747
LogPrintf("%s: parameter interaction: -connect set -> setting -dnsseed=0\n", __func__);
@@ -911,9 +911,9 @@ bool AppInitParameterInteraction()
911911
InitWarning(strprintf(_("Reducing -maxconnections from %d to %d, because of system limitations."), nUserMaxConnections, nMaxConnections));
912912

913913
// ********************************************************* Step 3: parameter-to-internal-flags
914-
if (gArgs.IsArgSet("-debug") > 0) {
914+
if (gArgs.IsArgSet("-debug")) {
915915
// Special-case: if -debug=0/-nodebug is set, turn off debugging messages
916-
const std::vector<std::string>& categories = gArgs.GetArgs("-debug");
916+
const std::vector<std::string> categories = gArgs.GetArgs("-debug");
917917

918918
if (find(categories.begin(), categories.end(), std::string("0")) == categories.end()) {
919919
for (const auto& cat : categories) {
@@ -928,9 +928,8 @@ bool AppInitParameterInteraction()
928928
}
929929

930930
// Now remove the logging categories which were explicitly excluded
931-
if (gArgs.IsArgSet("-debugexclude") > 0) {
932-
const std::vector<std::string>& excludedCategories = gArgs.GetArgs("-debugexclude");
933-
for (const auto& cat : excludedCategories) {
931+
if (gArgs.IsArgSet("-debugexclude")) {
932+
for (const std::string& cat : gArgs.GetArgs("-debugexclude")) {
934933
uint32_t flag = 0;
935934
if (!GetLogCategory(&flag, &cat)) {
936935
InitWarning(strprintf(_("Unsupported logging category %s=%s."), "-debugexclude", cat));
@@ -1105,10 +1104,9 @@ bool AppInitParameterInteraction()
11051104
if (!chainparams.MineBlocksOnDemand()) {
11061105
return InitError("BIP9 parameters may only be overridden on regtest.");
11071106
}
1108-
const std::vector<std::string>& deployments = gArgs.GetArgs("-bip9params");
1109-
for (auto i : deployments) {
1107+
for (const std::string& strDeployment : gArgs.GetArgs("-bip9params")) {
11101108
std::vector<std::string> vDeploymentParams;
1111-
boost::split(vDeploymentParams, i, boost::is_any_of(":"));
1109+
boost::split(vDeploymentParams, strDeployment, boost::is_any_of(":"));
11121110
if (vDeploymentParams.size() != 3) {
11131111
return InitError("BIP9 parameters malformed, expecting deployment:start:end");
11141112
}

0 commit comments

Comments
 (0)