Merge pull request #7119

dd5e689 protocol: add calls to reserve where appropriate (moneromooo-monero)
This commit is contained in:
luigi1111 2021-01-15 23:45:25 -05:00
commit d259ed0740
No known key found for this signature in database
GPG Key ID: F4ACA0183641E010

View File

@ -549,6 +549,7 @@ namespace cryptonote
} }
std::vector<tx_blob_entry> have_tx; std::vector<tx_blob_entry> have_tx;
have_tx.reserve(new_block.tx_hashes.size());
// Instead of requesting missing transactions by hash like BTC, // Instead of requesting missing transactions by hash like BTC,
// we do it by index (thanks to a suggestion from moneromooo) because // we do it by index (thanks to a suggestion from moneromooo) because
@ -557,6 +558,7 @@ namespace cryptonote
// Also, remember to pepper some whitespace changes around to bother // Also, remember to pepper some whitespace changes around to bother
// moneromooo ... only because I <3 him. // moneromooo ... only because I <3 him.
std::vector<uint64_t> need_tx_indices; std::vector<uint64_t> need_tx_indices;
need_tx_indices.reserve(new_block.tx_hashes.size());
transaction tx; transaction tx;
crypto::hash tx_hash; crypto::hash tx_hash;
@ -829,6 +831,7 @@ namespace cryptonote
} }
std::vector<crypto::hash> txids; std::vector<crypto::hash> txids;
txids.reserve(b.tx_hashes.size());
NOTIFY_NEW_FLUFFY_BLOCK::request fluffy_response; NOTIFY_NEW_FLUFFY_BLOCK::request fluffy_response;
fluffy_response.b.block = t_serializable_object_to_blob(b); fluffy_response.b.block = t_serializable_object_to_blob(b);
fluffy_response.current_blockchain_height = arg.current_blockchain_height; fluffy_response.current_blockchain_height = arg.current_blockchain_height;
@ -2189,6 +2192,7 @@ skip:
if (span.second > 0) if (span.second > 0)
{ {
is_next = true; is_next = true;
req.blocks.reserve(hashes.size());
for (const auto &hash: hashes) for (const auto &hash: hashes)
{ {
req.blocks.push_back(hash); req.blocks.push_back(hash);
@ -2247,6 +2251,7 @@ skip:
if (span.second > 0) if (span.second > 0)
{ {
is_next = true; is_next = true;
req.blocks.reserve(hashes.size());
for (const auto &hash: hashes) for (const auto &hash: hashes)
{ {
req.blocks.push_back(hash); req.blocks.push_back(hash);
@ -2280,6 +2285,7 @@ skip:
return false; return false;
} }
req.blocks.reserve(req.blocks.size() + span.second);
for (size_t n = 0; n < span.second; ++n) for (size_t n = 0; n < span.second; ++n)
{ {
req.blocks.push_back(context.m_needed_objects[n].first); req.blocks.push_back(context.m_needed_objects[n].first);
@ -2579,6 +2585,7 @@ skip:
} }
context.m_needed_objects.clear(); context.m_needed_objects.clear();
context.m_needed_objects.reserve(arg.m_block_ids.size());
uint64_t added = 0; uint64_t added = 0;
std::unordered_set<crypto::hash> blocks_found; std::unordered_set<crypto::hash> blocks_found;
bool first = true; bool first = true;