From cee47cc49577cc39863e020809dec9efc507c640 Mon Sep 17 00:00:00 2001 From: John Wiegley Date: Fri, 23 Mar 2012 16:59:06 -0500 Subject: Simplified some code in xact.cc --- src/balance.cc | 27 ++++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-) (limited to 'src/balance.cc') diff --git a/src/balance.cc b/src/balance.cc index cd25eede..ded3d38a 100644 --- a/src/balance.cc +++ b/src/balance.cc @@ -242,18 +242,27 @@ balance_t::strip_annotations(const keep_details_t& what_to_keep) const void balance_t::map_sorted_amounts(function fn) const { - typedef std::vector amounts_array; - amounts_array sorted; + if (! amounts.empty()) { + if (amounts.size() == 1) { + const amount_t& amount((*amounts.begin()).second); + if (amount) + fn(amount); + } + else { + typedef std::vector amounts_array; + amounts_array sorted; - foreach (const amounts_map::value_type& pair, amounts) - if (pair.second) - sorted.push_back(&pair.second); + foreach (const amounts_map::value_type& pair, amounts) + if (pair.second) + sorted.push_back(&pair.second); - std::stable_sort(sorted.begin(), sorted.end(), - commodity_t::compare_by_commodity()); + std::stable_sort(sorted.begin(), sorted.end(), + commodity_t::compare_by_commodity()); - foreach (const amount_t * amount, sorted) - fn(*amount); + foreach (const amount_t * amount, sorted) + fn(*amount); + } + } } namespace { -- cgit v1.2.3