From 581b3d5b9a3eebdd8f396d910386cadd9426b915 Mon Sep 17 00:00:00 2001 From: John Wiegley Date: Sat, 4 Mar 2006 14:46:04 +0000 Subject: *** no comment *** --- balance.h | 13 +++---------- value.cc | 28 ---------------------------- value.h | 57 ++++++++++++++++++++++++++++++--------------------------- 3 files changed, 33 insertions(+), 65 deletions(-) diff --git a/balance.h b/balance.h index 8f953fd5..2327d761 100644 --- a/balance.h +++ b/balance.h @@ -97,14 +97,10 @@ class balance_t } balance_t& operator-=(const amount_t& amt) { amounts_map::iterator i = amounts.find(&amt.commodity()); - if (i != amounts.end()) { + if (i != amounts.end()) (*i).second -= amt; - if (! (*i).second) - amounts.erase(&amt.commodity()); - } - else if (amt) { + else amounts.insert(amounts_pair(&amt.commodity(), - amt)); - } return *this; } template @@ -151,10 +147,7 @@ class balance_t balance_t& operator*=(const amount_t& amt) { // Multiplying by the null commodity causes all amounts to be // increased by the same factor. - if (! amt) { - amounts.clear(); - } - else if (! amt.commodity()) { + if (! amt.commodity()) { for (amounts_map::iterator i = amounts.begin(); i != amounts.end(); i++) diff --git a/value.cc b/value.cc index c9e39664..fbdda0ae 100644 --- a/value.cc +++ b/value.cc @@ -19,27 +19,6 @@ void value_t::destroy() } } -void value_t::simplify() -{ - if (! *this) { - *this = 0L; - return; - } - - if (type == BALANCE_PAIR && - (! ((balance_pair_t *) data)->cost || - ! *((balance_pair_t *) data)->cost)) - cast(BALANCE); - - if (type == BALANCE && - ((balance_t *) data)->amounts.size() == 1) - cast(AMOUNT); - - if (type == AMOUNT && - ! ((amount_t *) data)->commodity()) - cast(INTEGER); -} - value_t& value_t::operator=(const value_t& value) { if (this == &value) @@ -336,18 +315,11 @@ value_t& value_t::operator-=(const value_t& value) break; } - simplify(); - return *this; } value_t& value_t::operator*=(const value_t& value) { - if (! value) { - *this = 0L; - return *this; - } - switch (type) { case BOOLEAN: case INTEGER: diff --git a/value.h b/value.h index fc1517ed..59752dec 100644 --- a/value.h +++ b/value.h @@ -121,40 +121,43 @@ class value_t return *this = amount_t(value); } value_t& operator=(const amount_t& value) { - if ((amount_t *) data != &value) { - if (! value) { - return *this = 0L; - } else { - destroy(); - new((amount_t *)data) amount_t(value); - type = AMOUNT; - } - } + if (type == AMOUNT && + (amount_t *) data == &value) + return *this; + + destroy(); + new((amount_t *)data) amount_t(value); + type = AMOUNT; + return *this; } value_t& operator=(const balance_t& value) { - if ((balance_t *) data != &value) { - if (value.amounts.size() == 1) { - return *this = (*value.amounts.begin()).second; - } else { - destroy(); - new((balance_t *)data) balance_t(value); - type = BALANCE; - } + if (type == BALANCE && + (balance_t *) data == &value) + return *this; + + if (value.amounts.size() == 1) { + return *this = (*value.amounts.begin()).second; + } else { + destroy(); + new((balance_t *)data) balance_t(value); + type = BALANCE; + return *this; } - return *this; } value_t& operator=(const balance_pair_t& value) { - if ((balance_pair_t *) data != &value) { - if (! value.cost) { - return *this = value.quantity; - } else { - destroy(); - new((balance_pair_t *)data) balance_pair_t(value); - type = BALANCE_PAIR; - } + if (type == BALANCE_PAIR && + (balance_pair_t *) data == &value) + return *this; + + if (! value.cost) { + return *this = value.quantity; + } else { + destroy(); + new((balance_pair_t *)data) balance_pair_t(value); + type = BALANCE_PAIR; + return *this; } - return *this; } value_t& operator+=(const value_t& value); -- cgit v1.2.3