Skip to content

Commit fa89ca9

Browse files
author
MarcoFalke
committed
refactor: Use C++11 range based for loops to simplify rpc code
1 parent fa459bd commit fa89ca9

File tree

6 files changed

+17
-22
lines changed

6 files changed

+17
-22
lines changed

src/rpc/blockchain.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2407,7 +2407,7 @@ static const CRPCCommand commands[] =
24072407
{ "hidden", "dumptxoutset", &dumptxoutset, {"path"} },
24082408
};
24092409
// clang-format on
2410-
2411-
for (unsigned int vcidx = 0; vcidx < ARRAYLEN(commands); vcidx++)
2412-
t.appendCommand(commands[vcidx].name, &commands[vcidx]);
2410+
for (const auto& c : commands) {
2411+
t.appendCommand(c.name, &c);
2412+
}
24132413
}

src/rpc/mining.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1200,7 +1200,7 @@ static const CRPCCommand commands[] =
12001200
{ "hidden", "estimaterawfee", &estimaterawfee, {"conf_target", "threshold"} },
12011201
};
12021202
// clang-format on
1203-
1204-
for (unsigned int vcidx = 0; vcidx < ARRAYLEN(commands); vcidx++)
1205-
t.appendCommand(commands[vcidx].name, &commands[vcidx]);
1203+
for (const auto& c : commands) {
1204+
t.appendCommand(c.name, &c);
1205+
}
12061206
}

src/rpc/misc.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -619,7 +619,7 @@ static const CRPCCommand commands[] =
619619
{ "hidden", "echojson", &echo, {"arg0","arg1","arg2","arg3","arg4","arg5","arg6","arg7","arg8","arg9"}},
620620
};
621621
// clang-format on
622-
623-
for (unsigned int vcidx = 0; vcidx < ARRAYLEN(commands); vcidx++)
624-
t.appendCommand(commands[vcidx].name, &commands[vcidx]);
622+
for (const auto& c : commands) {
623+
t.appendCommand(c.name, &c);
624+
}
625625
}

src/rpc/net.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -796,7 +796,7 @@ static const CRPCCommand commands[] =
796796
{ "network", "getnodeaddresses", &getnodeaddresses, {"count"} },
797797
};
798798
// clang-format on
799-
800-
for (unsigned int vcidx = 0; vcidx < ARRAYLEN(commands); vcidx++)
801-
t.appendCommand(commands[vcidx].name, &commands[vcidx]);
799+
for (const auto& c : commands) {
800+
t.appendCommand(c.name, &c);
801+
}
802802
}

src/rpc/rawtransaction.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1821,7 +1821,7 @@ static const CRPCCommand commands[] =
18211821
{ "blockchain", "verifytxoutproof", &verifytxoutproof, {"proof"} },
18221822
};
18231823
// clang-format on
1824-
1825-
for (unsigned int vcidx = 0; vcidx < ARRAYLEN(commands); vcidx++)
1826-
t.appendCommand(commands[vcidx].name, &commands[vcidx]);
1824+
for (const auto& c : commands) {
1825+
t.appendCommand(c.name, &c);
1826+
}
18271827
}

src/rpc/server.cpp

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -256,13 +256,8 @@ static const CRPCCommand vRPCCommands[] =
256256

257257
CRPCTable::CRPCTable()
258258
{
259-
unsigned int vcidx;
260-
for (vcidx = 0; vcidx < (sizeof(vRPCCommands) / sizeof(vRPCCommands[0])); vcidx++)
261-
{
262-
const CRPCCommand *pcmd;
263-
264-
pcmd = &vRPCCommands[vcidx];
265-
mapCommands[pcmd->name].push_back(pcmd);
259+
for (const auto& c : vRPCCommands) {
260+
appendCommand(c.name, &c);
266261
}
267262
}
268263

0 commit comments

Comments
 (0)