Skip to content

Commit 506b700

Browse files
committed
Util: Remove redundant calls to gArgs.IsArgSet()
Return empty std::vector<std::string> with ArgsManager::GetArgs if nothing is set for that string
1 parent 234ffc6 commit 506b700

File tree

5 files changed

+16
-37
lines changed

5 files changed

+16
-37
lines changed

src/httprpc.cpp

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -92,10 +92,8 @@ static bool multiUserAuthorized(std::string strUserPass)
9292
std::string strUser = strUserPass.substr(0, strUserPass.find(":"));
9393
std::string strPass = strUserPass.substr(strUserPass.find(":") + 1);
9494

95-
if (gArgs.IsArgSet("-rpcauth")) {
95+
for (const std::string& strRPCAuth : gArgs.GetArgs("-rpcauth")) {
9696
//Search for multi-user login/pass "rpcauth" from config
97-
for (std::string strRPCAuth : gArgs.GetArgs("-rpcauth"))
98-
{
9997
std::vector<std::string> vFields;
10098
boost::split(vFields, strRPCAuth, boost::is_any_of(":$"));
10199
if (vFields.size() != 3) {
@@ -121,7 +119,6 @@ static bool multiUserAuthorized(std::string strUserPass)
121119
if (TimingResistantEqual(strHashFromPass, strHash)) {
122120
return true;
123121
}
124-
}
125122
}
126123
return false;
127124
}

src/httpserver.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -196,8 +196,7 @@ static bool InitHTTPAllowList()
196196
LookupHost("::1", localv6, false);
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
199-
if (gArgs.IsArgSet("-rpcallowip")) {
200-
for (const std::string& strAllow : gArgs.GetArgs("-rpcallowip")) {
199+
for (const std::string& strAllow : gArgs.GetArgs("-rpcallowip")) {
201200
CSubNet subnet;
202201
LookupSubNet(strAllow.c_str(), subnet);
203202
if (!subnet.IsValid()) {
@@ -207,7 +206,6 @@ static bool InitHTTPAllowList()
207206
return false;
208207
}
209208
rpc_allow_subnets.push_back(subnet);
210-
}
211209
}
212210
std::string strAllowed;
213211
for (const CSubNet& subnet : rpc_allow_subnets)

src/init.cpp

Lines changed: 9 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -880,9 +880,7 @@ bool AppInitParameterInteraction()
880880
}
881881

882882
// -bind and -whitebind can't be set when not listening
883-
size_t nUserBind =
884-
(gArgs.IsArgSet("-bind") ? gArgs.GetArgs("-bind").size() : 0) +
885-
(gArgs.IsArgSet("-whitebind") ? gArgs.GetArgs("-whitebind").size() : 0);
883+
size_t nUserBind = gArgs.GetArgs("-bind").size() + gArgs.GetArgs("-whitebind").size();
886884
if (nUserBind != 0 && !gArgs.GetBoolArg("-listen", DEFAULT_LISTEN)) {
887885
return InitError("Cannot set -bind or -whitebind together with -listen=0");
888886
}
@@ -920,15 +918,13 @@ bool AppInitParameterInteraction()
920918
}
921919

922920
// Now remove the logging categories which were explicitly excluded
923-
if (gArgs.IsArgSet("-debugexclude")) {
924-
for (const std::string& cat : gArgs.GetArgs("-debugexclude")) {
921+
for (const std::string& cat : gArgs.GetArgs("-debugexclude")) {
925922
uint32_t flag = 0;
926923
if (!GetLogCategory(&flag, &cat)) {
927924
InitWarning(strprintf(_("Unsupported logging category %s=%s."), "-debugexclude", cat));
928925
continue;
929926
}
930927
logCategories &= ~flag;
931-
}
932928
}
933929

934930
// Check for -debugnet
@@ -1238,13 +1234,10 @@ bool AppInitMain(boost::thread_group& threadGroup, CScheduler& scheduler)
12381234

12391235
// sanitize comments per BIP-0014, format user agent and check total size
12401236
std::vector<std::string> uacomments;
1241-
if (gArgs.IsArgSet("-uacomment")) {
1242-
for (std::string cmt : gArgs.GetArgs("-uacomment"))
1243-
{
1237+
for (const std::string& cmt : gArgs.GetArgs("-uacomment")) {
12441238
if (cmt != SanitizeString(cmt, SAFE_CHARS_UA_COMMENT))
12451239
return InitError(strprintf(_("User Agent comment (%s) contains unsafe characters."), cmt));
12461240
uacomments.push_back(cmt);
1247-
}
12481241
}
12491242
strSubVersion = FormatSubVersion(CLIENT_NAME, CLIENT_VERSION, uacomments);
12501243
if (strSubVersion.size() > MAX_SUBVERSION_LENGTH) {
@@ -1317,14 +1310,12 @@ bool AppInitMain(boost::thread_group& threadGroup, CScheduler& scheduler)
13171310
fDiscover = GetBoolArg("-discover", true);
13181311
fRelayTxes = !GetBoolArg("-blocksonly", DEFAULT_BLOCKSONLY);
13191312

1320-
if (gArgs.IsArgSet("-externalip")) {
1321-
for (const std::string& strAddr : gArgs.GetArgs("-externalip")) {
1313+
for (const std::string& strAddr : gArgs.GetArgs("-externalip")) {
13221314
CService addrLocal;
13231315
if (Lookup(strAddr.c_str(), addrLocal, GetListenPort(), fNameLookup) && addrLocal.IsValid())
13241316
AddLocal(addrLocal, LOCAL_MANUAL);
13251317
else
13261318
return InitError(ResolveErrMsg("externalip", strAddr));
1327-
}
13281319
}
13291320

13301321
#if ENABLE_ZMQ
@@ -1553,10 +1544,8 @@ bool AppInitMain(boost::thread_group& threadGroup, CScheduler& scheduler)
15531544
uiInterface.NotifyBlockTip.connect(BlockNotifyCallback);
15541545

15551546
std::vector<fs::path> vImportFiles;
1556-
if (gArgs.IsArgSet("-loadblock"))
1557-
{
1558-
for (const std::string& strFile : gArgs.GetArgs("-loadblock"))
1559-
vImportFiles.push_back(strFile);
1547+
for (const std::string& strFile : gArgs.GetArgs("-loadblock")) {
1548+
vImportFiles.push_back(strFile);
15601549
}
15611550

15621551
threadGroup.create_thread(boost::bind(&ThreadImport, vImportFiles));
@@ -1598,17 +1587,14 @@ bool AppInitMain(boost::thread_group& threadGroup, CScheduler& scheduler)
15981587
connOptions.nMaxOutboundTimeframe = nMaxOutboundTimeframe;
15991588
connOptions.nMaxOutboundLimit = nMaxOutboundLimit;
16001589

1601-
if (gArgs.IsArgSet("-bind")) {
1602-
for (const std::string& strBind : gArgs.GetArgs("-bind")) {
1590+
for (const std::string& strBind : gArgs.GetArgs("-bind")) {
16031591
CService addrBind;
16041592
if (!Lookup(strBind.c_str(), addrBind, GetListenPort(), false)) {
16051593
return InitError(ResolveErrMsg("bind", strBind));
16061594
}
16071595
connOptions.vBinds.push_back(addrBind);
1608-
}
16091596
}
1610-
if (gArgs.IsArgSet("-whitebind")) {
1611-
for (const std::string& strBind : gArgs.GetArgs("-whitebind")) {
1597+
for (const std::string& strBind : gArgs.GetArgs("-whitebind")) {
16121598
CService addrBind;
16131599
if (!Lookup(strBind.c_str(), addrBind, 0, false)) {
16141600
return InitError(ResolveErrMsg("whitebind", strBind));
@@ -1617,17 +1603,14 @@ bool AppInitMain(boost::thread_group& threadGroup, CScheduler& scheduler)
16171603
return InitError(strprintf(_("Need to specify a port with -whitebind: '%s'"), strBind));
16181604
}
16191605
connOptions.vWhiteBinds.push_back(addrBind);
1620-
}
16211606
}
16221607

1623-
if (gArgs.IsArgSet("-whitelist")) {
1624-
for (const auto& net : gArgs.GetArgs("-whitelist")) {
1608+
for (const auto& net : gArgs.GetArgs("-whitelist")) {
16251609
CSubNet subnet;
16261610
LookupSubNet(net.c_str(), subnet);
16271611
if (!subnet.IsValid())
16281612
return InitError(strprintf(_("Invalid netmask specified in -whitelist: '%s'"), net));
16291613
connOptions.vWhitelistedRange.push_back(subnet);
1630-
}
16311614
}
16321615

16331616
if (gArgs.IsArgSet("-seednode")) {

src/net.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1677,7 +1677,7 @@ void CConnman::ProcessOneShot()
16771677
void CConnman::ThreadOpenConnections()
16781678
{
16791679
// Connect to specific addresses
1680-
if (gArgs.IsArgSet("-connect") && gArgs.GetArgs("-connect").size() > 0)
1680+
if (gArgs.IsArgSet("-connect"))
16811681
{
16821682
for (int64_t nLoop = 0;; nLoop++)
16831683
{
@@ -1903,8 +1903,7 @@ void CConnman::ThreadOpenAddedConnections()
19031903
{
19041904
{
19051905
LOCK(cs_vAddedNodes);
1906-
if (gArgs.IsArgSet("-addnode"))
1907-
vAddedNodes = gArgs.GetArgs("-addnode");
1906+
vAddedNodes = gArgs.GetArgs("-addnode");
19081907
}
19091908

19101909
while (true)

src/util.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -420,7 +420,9 @@ void ArgsManager::ParseParameters(int argc, const char* const argv[])
420420
std::vector<std::string> ArgsManager::GetArgs(const std::string& strArg)
421421
{
422422
LOCK(cs_args);
423-
return mapMultiArgs.at(strArg);
423+
if (IsArgSet(strArg))
424+
return mapMultiArgs.at(strArg);
425+
return {};
424426
}
425427

426428
bool ArgsManager::IsArgSet(const std::string& strArg)

0 commit comments

Comments
 (0)