mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-11-13 07:28:59 +01:00
Convert ForEachNode* functions to take a templated function argument rather than a std::function to eliminate std::function overhead
This commit is contained in:
committed by
Cory Fields
parent
d1a2295f0d
commit
e700cd0bc8
73
src/net.cpp
73
src/net.cpp
@@ -2697,79 +2697,6 @@ bool CConnman::ForNode(NodeId id, std::function<bool(CNode* pnode)> func)
|
||||
return found != nullptr && func(found);
|
||||
}
|
||||
|
||||
bool CConnman::ForEachNodeContinueIf(std::function<bool(CNode* pnode)> func)
|
||||
{
|
||||
LOCK(cs_vNodes);
|
||||
for (auto&& node : vNodes)
|
||||
if(!func(node))
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool CConnman::ForEachNodeContinueIf(std::function<bool(const CNode* pnode)> func) const
|
||||
{
|
||||
LOCK(cs_vNodes);
|
||||
for (const auto& node : vNodes)
|
||||
if(!func(node))
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool CConnman::ForEachNodeContinueIfThen(std::function<bool(CNode* pnode)> pre, std::function<void()> post)
|
||||
{
|
||||
bool ret = true;
|
||||
LOCK(cs_vNodes);
|
||||
for (auto&& node : vNodes)
|
||||
if(!pre(node)) {
|
||||
ret = false;
|
||||
break;
|
||||
}
|
||||
post();
|
||||
return ret;
|
||||
}
|
||||
|
||||
bool CConnman::ForEachNodeContinueIfThen(std::function<bool(const CNode* pnode)> pre, std::function<void()> post) const
|
||||
{
|
||||
bool ret = true;
|
||||
LOCK(cs_vNodes);
|
||||
for (const auto& node : vNodes)
|
||||
if(!pre(node)) {
|
||||
ret = false;
|
||||
break;
|
||||
}
|
||||
post();
|
||||
return ret;
|
||||
}
|
||||
|
||||
void CConnman::ForEachNode(std::function<void(CNode* pnode)> func)
|
||||
{
|
||||
LOCK(cs_vNodes);
|
||||
for (auto&& node : vNodes)
|
||||
func(node);
|
||||
}
|
||||
|
||||
void CConnman::ForEachNode(std::function<void(const CNode* pnode)> func) const
|
||||
{
|
||||
LOCK(cs_vNodes);
|
||||
for (const auto& node : vNodes)
|
||||
func(node);
|
||||
}
|
||||
|
||||
void CConnman::ForEachNodeThen(std::function<void(CNode* pnode)> pre, std::function<void()> post)
|
||||
{
|
||||
LOCK(cs_vNodes);
|
||||
for (auto&& node : vNodes)
|
||||
pre(node);
|
||||
post();
|
||||
}
|
||||
|
||||
void CConnman::ForEachNodeThen(std::function<void(const CNode* pnode)> pre, std::function<void()> post) const
|
||||
{
|
||||
LOCK(cs_vNodes);
|
||||
for (const auto& node : vNodes)
|
||||
pre(node);
|
||||
post();
|
||||
}
|
||||
int64_t PoissonNextSend(int64_t nNow, int average_interval_seconds) {
|
||||
return nNow + (int64_t)(log1p(GetRand(1ULL << 48) * -0.0000000000000035527136788 /* -1/2^48 */) * average_interval_seconds * -1000000.0 + 0.5);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user