diff options
author | John Wiegley <johnw@newartisans.com> | 2004-08-26 02:01:29 -0400 |
---|---|---|
committer | John Wiegley <johnw@newartisans.com> | 2004-08-26 02:01:29 -0400 |
commit | 5f30c790dbc4a3ff469eb350e98817edd38d5de8 (patch) | |
tree | 30410c5c88a24e9a4b1986c7aaf09fbb0ceeb634 | |
parent | 69bd31b4d0386074713a35da319790b02648e479 (diff) | |
download | fork-ledger-5f30c790dbc4a3ff469eb350e98817edd38d5de8.tar.gz fork-ledger-5f30c790dbc4a3ff469eb350e98817edd38d5de8.tar.bz2 fork-ledger-5f30c790dbc4a3ff469eb350e98817edd38d5de8.zip |
fixed another memory strangeness (too much destruction)
-rw-r--r-- | value.cc | 1 | ||||
-rw-r--r-- | value.h | 69 | ||||
-rw-r--r-- | walk.h | 6 |
3 files changed, 48 insertions, 28 deletions
@@ -26,6 +26,7 @@ value_t& value_t::operator=(const value_t& value) return *this; destroy(); + switch (value.type) { case BOOLEAN: *((bool *) data) = *((bool *) value.data); @@ -37,7 +37,7 @@ class value_t type = INTEGER; } - value_t(const value_t& value) { + value_t(const value_t& value) : type(INTEGER) { DEBUG_PRINT("ledger.memory.ctors", "ctor value_t"); *this = value; } @@ -51,20 +51,17 @@ class value_t *((unsigned int *) data) = value; type = INTEGER; } - value_t(const amount_t& value) { + value_t(const amount_t& value) : type(INTEGER) { DEBUG_PRINT("ledger.memory.ctors", "ctor value_t"); - new((amount_t *)data) amount_t(value); - type = AMOUNT; + *this = value; } - value_t(const balance_t& value) { + value_t(const balance_t& value) : type(INTEGER) { DEBUG_PRINT("ledger.memory.ctors", "ctor value_t"); - new((balance_t *)data) balance_t(value); - type = BALANCE; + *this = value; } - value_t(const balance_pair_t& value) { + value_t(const balance_pair_t& value) : type(INTEGER) { DEBUG_PRINT("ledger.memory.ctors", "ctor value_t"); - new((balance_pair_t *)data) balance_pair_t(value); - type = BALANCE_PAIR; + *this = value; } ~value_t() { @@ -76,33 +73,55 @@ class value_t value_t& operator=(const value_t& value); value_t& operator=(const bool value) { - destroy(); - *((bool *) data) = value; - type = BOOLEAN; + if ((bool *) data != &value) { + destroy(); + *((bool *) data) = value; + type = BOOLEAN; + } return *this; } value_t& operator=(const unsigned int value) { - destroy(); - *((unsigned int *) data) = value; - type = INTEGER; + if ((unsigned int *) data != &value) { + destroy(); + *((unsigned int *) data) = value; + type = INTEGER; + } return *this; } value_t& operator=(const amount_t& value) { - destroy(); - new((amount_t *)data) amount_t(value); - type = AMOUNT; + if ((amount_t *) data != &value) { + if (! value) { + return *this = 0U; + } else { + destroy(); + new((amount_t *)data) amount_t(value); + type = AMOUNT; + } + } return *this; } value_t& operator=(const balance_t& value) { - destroy(); - new((balance_t *)data) balance_t(value); - type = BALANCE; + 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; + } + } return *this; } value_t& operator=(const balance_pair_t& value) { - destroy(); - new((balance_pair_t *)data) balance_pair_t(value); - type = BALANCE_PAIR; + 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; + } + } return *this; } @@ -40,6 +40,9 @@ struct item_handler { template <typename T> class compare_items { + value_t left_result; + value_t right_result; + const value_expr_t * sort_order; public: @@ -52,9 +55,6 @@ class compare_items { assert(left); assert(right); - value_t left_result; - value_t right_result; - sort_order->compute(left_result, details_t(left)); sort_order->compute(right_result, details_t(right)); |