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
90
src/net.h
90
src/net.h
@@ -129,14 +129,88 @@ public:
|
||||
bool CheckIncomingNonce(uint64_t nonce);
|
||||
|
||||
bool ForNode(NodeId id, std::function<bool(CNode* pnode)> func);
|
||||
bool ForEachNodeContinueIf(std::function<bool(CNode* pnode)> func);
|
||||
bool ForEachNodeContinueIf(std::function<bool(const CNode* pnode)> func) const;
|
||||
bool ForEachNodeContinueIfThen(std::function<bool(CNode* pnode)> pre, std::function<void()> post);
|
||||
bool ForEachNodeContinueIfThen(std::function<bool(const CNode* pnode)> pre, std::function<void()> post) const;
|
||||
void ForEachNode(std::function<void(CNode* pnode)> func);
|
||||
void ForEachNode(std::function<void(const CNode* pnode)> func) const;
|
||||
void ForEachNodeThen(std::function<void(CNode* pnode)> pre, std::function<void()> post);
|
||||
void ForEachNodeThen(std::function<void(const CNode* pnode)> pre, std::function<void()> post) const;
|
||||
|
||||
template<typename Callable>
|
||||
bool ForEachNodeContinueIf(Callable&& func)
|
||||
{
|
||||
LOCK(cs_vNodes);
|
||||
for (auto&& node : vNodes)
|
||||
if(!func(node))
|
||||
return false;
|
||||
return true;
|
||||
};
|
||||
|
||||
template<typename Callable>
|
||||
bool ForEachNodeContinueIf(Callable&& func) const
|
||||
{
|
||||
LOCK(cs_vNodes);
|
||||
for (const auto& node : vNodes)
|
||||
if(!func(node))
|
||||
return false;
|
||||
return true;
|
||||
};
|
||||
|
||||
template<typename Callable, typename CallableAfter>
|
||||
bool ForEachNodeContinueIfThen(Callable&& pre, CallableAfter&& post)
|
||||
{
|
||||
bool ret = true;
|
||||
LOCK(cs_vNodes);
|
||||
for (auto&& node : vNodes)
|
||||
if(!pre(node)) {
|
||||
ret = false;
|
||||
break;
|
||||
}
|
||||
post();
|
||||
return ret;
|
||||
};
|
||||
|
||||
template<typename Callable, typename CallableAfter>
|
||||
bool ForEachNodeContinueIfThen(Callable&& pre, CallableAfter&& post) const
|
||||
{
|
||||
bool ret = true;
|
||||
LOCK(cs_vNodes);
|
||||
for (const auto& node : vNodes)
|
||||
if(!pre(node)) {
|
||||
ret = false;
|
||||
break;
|
||||
}
|
||||
post();
|
||||
return ret;
|
||||
};
|
||||
|
||||
template<typename Callable>
|
||||
void ForEachNode(Callable&& func)
|
||||
{
|
||||
LOCK(cs_vNodes);
|
||||
for (auto&& node : vNodes)
|
||||
func(node);
|
||||
};
|
||||
|
||||
template<typename Callable>
|
||||
void ForEachNode(Callable&& func) const
|
||||
{
|
||||
LOCK(cs_vNodes);
|
||||
for (const auto& node : vNodes)
|
||||
func(node);
|
||||
};
|
||||
|
||||
template<typename Callable, typename CallableAfter>
|
||||
void ForEachNodeThen(Callable&& pre, CallableAfter&& post)
|
||||
{
|
||||
LOCK(cs_vNodes);
|
||||
for (auto&& node : vNodes)
|
||||
pre(node);
|
||||
post();
|
||||
};
|
||||
|
||||
template<typename Callable, typename CallableAfter>
|
||||
void ForEachNodeThen(Callable&& pre, CallableAfter&& post) const
|
||||
{
|
||||
LOCK(cs_vNodes);
|
||||
for (const auto& node : vNodes)
|
||||
pre(node);
|
||||
post();
|
||||
};
|
||||
|
||||
void RelayTransaction(const CTransaction& tx);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user