mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-01-20 15:19:07 +01:00
refactor: return reference instead of pointer
The return value of BlockManager::GetFirstBlock must always be non-null. This can be inferred by the implementation, which has an assertion that the return value is not null. A raw pointer should only be returned if the result may be null. In this case a reference is more appropriate.
This commit is contained in:
@@ -588,7 +588,7 @@ bool BlockManager::IsBlockPruned(const CBlockIndex& block) const
|
||||
return m_have_pruned && !(block.nStatus & BLOCK_HAVE_DATA) && (block.nTx > 0);
|
||||
}
|
||||
|
||||
const CBlockIndex* BlockManager::GetFirstBlock(const CBlockIndex& upper_block, uint32_t status_mask, const CBlockIndex* lower_block) const
|
||||
const CBlockIndex& BlockManager::GetFirstBlock(const CBlockIndex& upper_block, uint32_t status_mask, const CBlockIndex* lower_block) const
|
||||
{
|
||||
AssertLockHeld(::cs_main);
|
||||
const CBlockIndex* last_block = &upper_block;
|
||||
@@ -596,7 +596,7 @@ const CBlockIndex* BlockManager::GetFirstBlock(const CBlockIndex& upper_block, u
|
||||
while (last_block->pprev && ((last_block->pprev->nStatus & status_mask) == status_mask)) {
|
||||
if (lower_block) {
|
||||
// Return if we reached the lower_block
|
||||
if (last_block == lower_block) return lower_block;
|
||||
if (last_block == lower_block) return *lower_block;
|
||||
// if range was surpassed, means that 'lower_block' is not part of the 'upper_block' chain
|
||||
// and so far this is not allowed.
|
||||
assert(last_block->nHeight >= lower_block->nHeight);
|
||||
@@ -604,13 +604,13 @@ const CBlockIndex* BlockManager::GetFirstBlock(const CBlockIndex& upper_block, u
|
||||
last_block = last_block->pprev;
|
||||
}
|
||||
assert(last_block != nullptr);
|
||||
return last_block;
|
||||
return *last_block;
|
||||
}
|
||||
|
||||
bool BlockManager::CheckBlockDataAvailability(const CBlockIndex& upper_block, const CBlockIndex& lower_block)
|
||||
{
|
||||
if (!(upper_block.nStatus & BLOCK_HAVE_DATA)) return false;
|
||||
return GetFirstBlock(upper_block, BLOCK_HAVE_DATA, &lower_block) == &lower_block;
|
||||
return &GetFirstBlock(upper_block, BLOCK_HAVE_DATA, &lower_block) == &lower_block;
|
||||
}
|
||||
|
||||
// If we're using -prune with -reindex, then delete block files that will be ignored by the
|
||||
|
||||
Reference in New Issue
Block a user