File tree Expand file tree Collapse file tree 1 file changed +5
-10
lines changed Expand file tree Collapse file tree 1 file changed +5
-10
lines changed Original file line number Diff line number Diff line change @@ -50,22 +50,17 @@ CBlockIndex* BlockManager::AddToBlockIndex(const CBlockHeader& block)
50
50
{
51
51
AssertLockHeld (cs_main);
52
52
53
- // Check for duplicate
54
- uint256 hash = block.GetHash ();
55
- BlockMap::iterator it = m_block_index.find (hash);
56
- if (it != m_block_index.end ()) {
57
- return &it->second ;
53
+ auto [mi, inserted] = m_block_index.try_emplace (block.GetHash (), block);
54
+ if (!inserted) {
55
+ return &mi->second ;
58
56
}
57
+ CBlockIndex* pindexNew = &(*mi).second ;
59
58
60
- // Construct new block index object
61
- CBlockIndex new_index{block};
62
59
// We assign the sequence id to blocks only when the full data is available,
63
60
// to avoid miners withholding blocks but broadcasting headers, to get a
64
61
// competitive advantage.
65
- new_index.nSequenceId = 0 ;
66
- BlockMap::iterator mi = m_block_index.insert (std::make_pair (hash, std::move (new_index))).first ;
62
+ pindexNew->nSequenceId = 0 ;
67
63
68
- CBlockIndex* pindexNew = &(*mi).second ;
69
64
pindexNew->phashBlock = &((*mi).first );
70
65
BlockMap::iterator miPrev = m_block_index.find (block.hashPrevBlock );
71
66
if (miPrev != m_block_index.end ()) {
You can’t perform that action at this time.
0 commit comments