diff options
Diffstat (limited to 'src/node')
-rw-r--r-- | src/node/blockstorage.cpp | 18 |
1 files changed, 6 insertions, 12 deletions
diff --git a/src/node/blockstorage.cpp b/src/node/blockstorage.cpp index a13c1a9956..0619af5426 100644 --- a/src/node/blockstorage.cpp +++ b/src/node/blockstorage.cpp @@ -208,19 +208,13 @@ CBlockIndex* BlockManager::InsertBlockIndex(const uint256& hash) return nullptr; } - // Return existing - BlockMap::iterator mi = m_block_index.find(hash); - if (mi != m_block_index.end()) { - return &(*mi).second; + // Return existing or create new + auto [mi, inserted] = m_block_index.try_emplace(hash); + CBlockIndex* pindex = &(*mi).second; + if (inserted) { + pindex->phashBlock = &((*mi).first); } - - // Create new - CBlockIndex new_index{}; - mi = m_block_index.insert(std::make_pair(hash, std::move(new_index))).first; - CBlockIndex* pindexNew = &(*mi).second; - pindexNew->phashBlock = &((*mi).first); - - return pindexNew; + return pindex; } bool BlockManager::LoadBlockIndex( |