Skip to content

Commit

Permalink
Merge pull request #745 from evoskuil/master
Browse files Browse the repository at this point in the history
Remove unnecessary shared_ptr copy.
  • Loading branch information
evoskuil authored Mar 8, 2025
2 parents 15f37e4 + 8f51963 commit c7f7502
Showing 1 changed file with 2 additions and 12 deletions.
14 changes: 2 additions & 12 deletions src/protocols/protocol_block_in_31800.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -281,8 +281,8 @@ bool protocol_block_in_31800::handle_receive_block(const code& ec,
// Preconditions.
// ........................................................................

// Intentional pointer copy.
const auto block = message->block_ptr;
// message lifetime is guaranteed, and therefore block_ptr is as well.
const auto& block = message->block_ptr;
const auto& hash = block->get_hash();
const auto it = map_->find(hash);
auto& query = archive();
Expand Down Expand Up @@ -353,11 +353,6 @@ bool protocol_block_in_31800::handle_receive_block(const code& ec,
return false;
}

// ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
// This is an attempt to keep the shared pointer in scope.
// Given that block is const this could also be reordered prior to check().
// But this is not called in this scope, only by message deserialization.
// ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
if (!block->is_valid())
{
stop(fault(error::protocol2));
Expand All @@ -372,11 +367,6 @@ bool protocol_block_in_31800::handle_receive_block(const code& ec,

notify(ec, chase::checked, height);
fire(events::block_archived, height);

// ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
// block->serialized_size may keep block in scope during set_code above.
// However the compiler may reorder this calculation since block is const.
// ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
count(block->serialized_size(true));
map_->erase(it);
if (is_idle())
Expand Down

0 comments on commit c7f7502

Please sign in to comment.