Skip to content

Commit

Permalink
Remove unnecessary copies (#2026)
Browse files Browse the repository at this point in the history
  • Loading branch information
wezrule authored and Russel Waters committed Jun 11, 2019
1 parent 0220376 commit dd9a4f9
Show file tree
Hide file tree
Showing 14 changed files with 84 additions and 81 deletions.
18 changes: 9 additions & 9 deletions nano/nano_node/entry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -242,15 +242,15 @@ int main (int argc, char * const * argv)
nano::uint128_t total;
for (auto i (node.node->store.representation_begin (transaction)), n (node.node->store.representation_end ()); i != n; ++i)
{
nano::account account (i->first);
nano::account const & account (i->first);
auto amount (node.node->store.representation_get (transaction, account));
total += amount;
std::cout << boost::str (boost::format ("%1% %2% %3%\n") % account.to_account () % amount.convert_to<std::string> () % total.convert_to<std::string> ());
}
std::map<nano::account, nano::uint128_t> calculated;
for (auto i (node.node->store.latest_begin (transaction)), n (node.node->store.latest_end ()); i != n; ++i)
{
nano::account_info info (i->second);
nano::account_info const & info (i->second);
nano::block_hash rep_block (node.node->ledger.representative_calculated (transaction, info.head));
auto block (node.node->store.block_get (transaction, rep_block));
calculated[block->representative ()] += info.balance.number ();
Expand Down Expand Up @@ -783,8 +783,8 @@ int main (int argc, char * const * argv)
{
std::cout << boost::str (boost::format ("%1% accounts validated\n") % count);
}
nano::account_info info (i->second);
nano::account account (i->first);
nano::account_info const & info (i->second);
nano::account const & account (i->first);

if (info.confirmation_height > info.block_count)
{
Expand Down Expand Up @@ -885,8 +885,8 @@ int main (int argc, char * const * argv)
{
std::cout << boost::str (boost::format ("%1% pending blocks validated\n") % count);
}
nano::pending_key key (i->first);
nano::pending_info info (i->second);
nano::pending_key const & key (i->first);
nano::pending_info const & info (i->second);
// Check block existance
auto block (node.node->store.block_get (transaction, key.hash));
if (block == nullptr)
Expand Down Expand Up @@ -947,8 +947,8 @@ int main (int argc, char * const * argv)
std::cout << boost::str (boost::format ("Performing bootstrap emulation, %1% blocks in ledger...") % block_count) << std::endl;
for (auto i (node.node->store.latest_begin (transaction)), n (node.node->store.latest_end ()); i != n; ++i)
{
nano::account account (i->first);
nano::account_info info (i->second);
nano::account const & account (i->first);
nano::account_info const & info (i->second);
auto hash (info.head);
while (!hash.is_zero ())
{
Expand Down Expand Up @@ -1006,7 +1006,7 @@ int main (int argc, char * const * argv)
uint64_t sum = 0;
for (auto i (node.node->store.latest_begin (transaction)), n (node.node->store.latest_end ()); i != n; ++i)
{
nano::account_info info (i->second);
nano::account_info const & info (i->second);
sum += info.confirmation_height;
}
std::cout << "Total cemented block count: " << sum << std::endl;
Expand Down
2 changes: 1 addition & 1 deletion nano/node/active_transactions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ void nano::active_transactions::confirm_frontiers (nano::transaction const & tra
size_t elections_count (0);
for (auto i (node.store.latest_begin (transaction_a, next_frontier_account)), n (node.store.latest_end ()); i != n && !stopped && elections_count < max_elections; ++i)
{
nano::account_info info (i->second);
nano::account_info const & info (i->second);
if (info.block_count != info.confirmation_height)
{
auto block (node.store.block_get (transaction_a, info.head));
Expand Down
16 changes: 8 additions & 8 deletions nano/node/blockprocessor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -137,12 +137,12 @@ void nano::block_processor::verify_state_blocks (nano::transaction const & trans
std::deque<nano::unchecked_info> items;
for (auto i (0); i < max_count && !state_blocks.empty (); i++)
{
auto item (state_blocks.front ());
state_blocks.pop_front ();
auto & item (state_blocks.front ());
if (!node.ledger.store.block_exists (transaction_a, item.block->type (), item.block->hash ()))
{
items.push_back (item);
items.push_back (std::move (item));
}
state_blocks.pop_front ();
}
lock_a.unlock ();
if (!items.empty ())
Expand All @@ -166,7 +166,7 @@ void nano::block_processor::verify_state_blocks (nano::transaction const & trans
verifications.resize (size, 0);
for (auto i (0); i < size; ++i)
{
auto item (items[i]);
auto & item (items[i]);
hashes.push_back (item.block->hash ());
messages.push_back (hashes.back ().bytes.data ());
lengths.push_back (sizeof (decltype (hashes)::value_type));
Expand All @@ -190,27 +190,27 @@ void nano::block_processor::verify_state_blocks (nano::transaction const & trans
for (auto i (0); i < size; ++i)
{
assert (verifications[i] == 1 || verifications[i] == 0);
auto item (items.front ());
auto & item (items.front ());
if (!item.block->link ().is_zero () && node.ledger.is_epoch_link (item.block->link ()))
{
// Epoch blocks
if (verifications[i] == 1)
{
item.verified = nano::signature_verification::valid_epoch;
blocks.push_back (item);
blocks.push_back (std::move (item));
}
else
{
// Possible regular state blocks with epoch link (send subtype)
item.verified = nano::signature_verification::unknown;
blocks.push_back (item);
blocks.push_back (std::move (item));
}
}
else if (verifications[i] == 1)
{
// Non epoch blocks
item.verified = nano::signature_verification::valid;
blocks.push_back (item);
blocks.push_back (std::move (item));
}
items.pop_front ();
}
Expand Down
22 changes: 12 additions & 10 deletions nano/node/bootstrap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -256,21 +256,22 @@ void nano::frontier_req_client::next (nano::transaction const & transaction_a)
size_t max_size (128);
for (auto i (connection->node->store.latest_begin (transaction_a, current.number () + 1)), n (connection->node->store.latest_end ()); i != n && accounts.size () != max_size; ++i)
{
nano::account_info info (i->second);
accounts.push_back (std::make_pair (nano::account (i->first), info.head));
nano::account_info const & info (i->second);
nano::account const & account (i->first);
accounts.emplace_back (account, info.head);
}
/* If loop breaks before max_size, then latest_end () is reached
Add empty record to finish frontier_req_server */
if (accounts.size () != max_size)
{
accounts.push_back (std::make_pair (nano::account (0), nano::block_hash (0)));
accounts.emplace_back (nano::account (0), nano::block_hash (0));
}
}
// Retrieving accounts from deque
auto account_pair (accounts.front ());
accounts.pop_front ();
auto const & account_pair (accounts.front ());
current = account_pair.first;
frontier = account_pair.second;
accounts.pop_front ();
}

nano::bulk_pull_client::bulk_pull_client (std::shared_ptr<nano::bootstrap_client> connection_a, nano::pull_info const & pull_a) :
Expand Down Expand Up @@ -3234,24 +3235,25 @@ void nano::frontier_req_server::next ()
auto transaction (connection->node->store.tx_begin_read ());
for (auto i (connection->node->store.latest_begin (transaction, current.number () + 1)), n (connection->node->store.latest_end ()); i != n && accounts.size () != max_size; ++i)
{
nano::account_info info (i->second);
nano::account_info const & info (i->second);
if (!skip_old || (now - info.modified) <= request->age)
{
accounts.push_back (std::make_pair (nano::account (i->first), info.head));
nano::account const & account (i->first);
accounts.emplace_back (account, info.head);
}
}
/* If loop breaks before max_size, then latest_end () is reached
Add empty record to finish frontier_req_server */
if (accounts.size () != max_size)
{
accounts.push_back (std::make_pair (nano::account (0), nano::block_hash (0)));
accounts.emplace_back (nano::account (0), nano::block_hash (0));
}
}
// Retrieving accounts from deque
auto account_pair (accounts.front ());
accounts.pop_front ();
auto const & account_pair (accounts.front ());
current = account_pair.first;
frontier = account_pair.second;
accounts.pop_front ();
}

void nano::pulls_cache::add (nano::pull_info const & pull_a)
Expand Down
4 changes: 2 additions & 2 deletions nano/node/cli.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -603,7 +603,7 @@ std::error_code nano::handle_node_options (boost::program_options::variables_map
std::cout << boost::str (boost::format ("Seed: %1%\n") % seed.data.to_string ());
for (auto i (existing->second->store.begin (transaction)), m (existing->second->store.end ()); i != m; ++i)
{
nano::account account (i->first);
nano::account const & account (i->first);
nano::raw_key key;
auto error (existing->second->store.fetch (transaction, account, key));
assert (!error);
Expand Down Expand Up @@ -930,7 +930,7 @@ std::error_code nano::handle_node_options (boost::program_options::variables_map
auto transaction (node.node->store.tx_begin_read ());
for (auto i (node.node->store.vote_begin (transaction)), n (node.node->store.vote_end ()); i != n; ++i)
{
auto vote (i->second);
auto const & vote (i->second);
std::cerr << boost::str (boost::format ("%1%\n") % vote->to_json ());
}
}
Expand Down
2 changes: 1 addition & 1 deletion nano/node/election.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ bool nano::election::have_quorum (nano::tally_t const & tally_a, nano::uint128_t
if (tally_sum >= node.config.online_weight_minimum.number ())
{
auto i (tally_a.begin ());
auto first (i->first);
auto const & first (i->first);
++i;
auto second (i != tally_a.end () ? i->first : 0);
auto delta_l (node.delta ());
Expand Down
Loading

0 comments on commit dd9a4f9

Please sign in to comment.