diff options
author | moneromooo-monero <moneromooo-monero@users.noreply.github.com> | 2018-04-16 00:16:02 +0100 |
---|---|---|
committer | moneromooo-monero <moneromooo-monero@users.noreply.github.com> | 2018-06-26 22:14:21 +0100 |
commit | ed2c81ed95be71bace897e62a0c241068cfde7be (patch) | |
tree | a6077a06dc4aa4bcf127f26092cb43f3c3742e3b /src/rpc/daemon_handler.cpp | |
parent | rpc: sanity check on number of txes in a block (diff) | |
download | monero-ed2c81ed95be71bace897e62a0c241068cfde7be.tar.xz |
replace std::list with std::vector on some hot paths
also use reserve where appropriate
Diffstat (limited to 'src/rpc/daemon_handler.cpp')
-rw-r--r-- | src/rpc/daemon_handler.cpp | 30 |
1 files changed, 7 insertions, 23 deletions
diff --git a/src/rpc/daemon_handler.cpp b/src/rpc/daemon_handler.cpp index 39f169cdf..582a3440b 100644 --- a/src/rpc/daemon_handler.cpp +++ b/src/rpc/daemon_handler.cpp @@ -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); |