aboutsummaryrefslogtreecommitdiff
path: root/src/rest.cpp
diff options
context:
space:
mode:
authorCarl Dong <contact@carldong.me>2021-04-12 21:34:42 -0400
committerCarl Dong <contact@carldong.me>2021-04-14 11:17:31 -0400
commit586190f0b4740457cb86cba632e3d64e6dfe9b0c (patch)
tree667f7c58a4c5c3d844fe22c279252010575d81da /src/rest.cpp
parentbc3bd369027273278a0541f3b991eb71de831aa2 (diff)
downloadbitcoin-586190f0b4740457cb86cba632e3d64e6dfe9b0c.tar.xz
rpc/rest: Take and reuse local Chain/ChainState obj
In all rest/rpc-related modules, if there are multiple calls to ActiveChain{,State}(), and the calls fall under the same ::cs_main lock, we can simply take a local reference and use/reuse it instead of calling ActiveChain{,State}() again and again.
Diffstat (limited to 'src/rest.cpp')
-rw-r--r--src/rest.cpp7
1 files changed, 4 insertions, 3 deletions
diff --git a/src/rest.cpp b/src/rest.cpp
index eea0d67882..9b9f414e6c 100644
--- a/src/rest.cpp
+++ b/src/rest.cpp
@@ -182,13 +182,14 @@ static bool rest_headers(const std::any& context,
{
ChainstateManager& chainman = EnsureAnyChainman(context);
LOCK(cs_main);
- tip = chainman.ActiveChain().Tip();
+ CChain& active_chain = chainman.ActiveChain();
+ tip = active_chain.Tip();
const CBlockIndex* pindex = chainman.m_blockman.LookupBlockIndex(hash);
- while (pindex != nullptr && chainman.ActiveChain().Contains(pindex)) {
+ while (pindex != nullptr && active_chain.Contains(pindex)) {
headers.push_back(pindex);
if (headers.size() == (unsigned long)count)
break;
- pindex = chainman.ActiveChain().Next(pindex);
+ pindex = active_chain.Next(pindex);
}
}