summaryrefslogtreecommitdiff
path: root/value.h
diff options
context:
space:
mode:
Diffstat (limited to 'value.h')
-rw-r--r--value.h57
1 files changed, 30 insertions, 27 deletions
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);