replace std::list with std::vector on some hot paths

also use reserve where appropriate
This commit is contained in:
moneromooo-monero 2018-04-16 00:16:02 +01:00
parent 209ec963b5
commit ed2c81ed95
No known key found for this signature in database
GPG key ID: 686F07454D6CEFC3
28 changed files with 257 additions and 233 deletions

View file

@ -50,7 +50,7 @@ namespace rpc
void DaemonHandler::handle(const GetBlocksFast::Request& req, GetBlocksFast::Response& res)
{
std::list<std::pair<blobdata, std::list<blobdata> > > blocks;
std::vector<std::pair<blobdata, std::vector<blobdata> > > blocks;
if(!m_core.find_blockchain_supplement(req.start_height, req.block_ids, blocks, res.current_height, res.start_height, req.prune, COMMAND_RPC_GET_BLOCKS_FAST_MAX_COUNT))
{
@ -62,9 +62,6 @@ namespace rpc
res.blocks.resize(blocks.size());
res.output_indices.resize(blocks.size());
//TODO: really need to switch uses of std::list to std::vector unless
// it's a huge performance concern
auto it = blocks.begin();
uint64_t block_count = 0;
@ -89,7 +86,7 @@ namespace rpc
res.error_details = "incorrect number of transactions retrieved for block";
return;
}
std::list<transaction> txs;
std::vector<transaction> txs;
for (const auto& blob : it->second)
{
txs.resize(txs.size() + 1);
@ -163,10 +160,10 @@ namespace rpc
void DaemonHandler::handle(const GetTransactions::Request& req, GetTransactions::Response& res)
{
std::list<cryptonote::transaction> found_txs;
std::list<crypto::hash> missed_hashes;
std::vector<cryptonote::transaction> found_txs_vec;
std::vector<crypto::hash> missed_vec;
bool r = m_core.get_transactions(req.tx_hashes, found_txs, missed_hashes);
bool r = m_core.get_transactions(req.tx_hashes, found_txs_vec, missed_vec);
// TODO: consider fixing core::get_transactions to not hide exceptions
if (!r)
@ -176,20 +173,7 @@ namespace rpc
return;
}
size_t num_found = found_txs.size();
// std::list is annoying
std::vector<cryptonote::transaction> found_txs_vec
{
std::make_move_iterator(std::begin(found_txs)),
std::make_move_iterator(std::end(found_txs))
};
std::vector<crypto::hash> missed_vec
{
std::make_move_iterator(std::begin(missed_hashes)),
std::make_move_iterator(std::end(missed_hashes))
};
size_t num_found = found_txs_vec.size();
std::vector<uint64_t> heights(num_found);
std::vector<bool> in_pool(num_found, false);
@ -204,7 +188,7 @@ namespace rpc
// if any missing from blockchain, check in tx pool
if (!missed_vec.empty())
{
std::list<cryptonote::transaction> pool_txs;
std::vector<cryptonote::transaction> pool_txs;
m_core.get_pool_transactions(pool_txs);