Avoid unnecessary object copying when using foreach

This commit is contained in:
John Wiegley 2010-06-03 17:43:38 -04:00
parent c3cc935ba6
commit 27b86a5388
4 changed files with 7 additions and 7 deletions

View file

@ -262,7 +262,7 @@ commodity_t::varied_history_t::find_price(const commodity_t& source,
price_point_t best;
bool found = false;
foreach (history_by_commodity_map::value_type hist, histories) {
foreach (const history_by_commodity_map::value_type& hist, histories) {
commodity_t& comm(*hist.first);
if (comm == source)
continue;

View file

@ -50,7 +50,7 @@ void post_splitter::print_title(const value_t& val)
void post_splitter::flush()
{
foreach (value_to_posts_map::value_type pair, posts_map) {
foreach (value_to_posts_map::value_type& pair, posts_map) {
preflush_func(pair.first);
foreach (post_t * post, pair.second)
@ -894,7 +894,7 @@ void posts_as_equity::report_subtotal()
value_t total = 0L;
foreach (values_map::value_type& pair, values) {
if (pair.second.value.is_balance()) {
foreach (balance_t::amounts_map::value_type amount_pair,
foreach (const balance_t::amounts_map::value_type& amount_pair,
pair.second.value.as_balance().amounts)
handle_value(amount_pair.second, pair.second.account, &xact, temps,
handler);
@ -907,7 +907,7 @@ void posts_as_equity::report_subtotal()
values.clear();
if (total.is_balance()) {
foreach (balance_t::amounts_map::value_type pair,
foreach (const balance_t::amounts_map::value_type& pair,
total.as_balance().amounts) {
post_t& balance_post = temps.create_post(xact, balance_account);
balance_post.amount = - pair.second;

View file

@ -94,9 +94,9 @@ void posts_commodities_iterator::reset(journal_t& journal)
comm->varied_history()) {
account_t * account = journal.master->find_account(comm->symbol());
foreach (commodity_t::history_by_commodity_map::value_type pair,
foreach (commodity_t::history_by_commodity_map::value_type& pair,
history->histories) {
foreach (commodity_t::history_map::value_type hpair,
foreach (commodity_t::history_map::value_type& hpair,
pair.second.prices) {
xact_t * xact;
string symbol = hpair.second.commodity().symbol();

View file

@ -86,7 +86,7 @@ public:
virtual ~commodity_pool_t() {
TRACE_DTOR(commodity_pool_t);
foreach (commodities_map::value_type pair, commodities)
foreach (commodities_map::value_type& pair, commodities)
checked_delete(pair.second);
}