diff options
author | John Wiegley <johnw@newartisans.com> | 2012-03-23 16:59:06 -0500 |
---|---|---|
committer | John Wiegley <johnw@newartisans.com> | 2012-03-23 16:59:06 -0500 |
commit | cee47cc49577cc39863e020809dec9efc507c640 (patch) | |
tree | 577dcc4771ca8976107805f551047cc549a37dae /src/balance.cc | |
parent | 4b057599626538a0d1463c63f2110d2fe5baa2e6 (diff) | |
download | fork-ledger-cee47cc49577cc39863e020809dec9efc507c640.tar.gz fork-ledger-cee47cc49577cc39863e020809dec9efc507c640.tar.bz2 fork-ledger-cee47cc49577cc39863e020809dec9efc507c640.zip |
Simplified some code in xact.cc
Diffstat (limited to 'src/balance.cc')
-rw-r--r-- | src/balance.cc | 27 |
1 files changed, 18 insertions, 9 deletions
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<void(const amount_t&)> fn) const { - typedef std::vector<const amount_t *> 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<const amount_t *> 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 { |