fixed another memory strangeness (too much destruction)
This commit is contained in:
parent
69bd31b4d0
commit
5f30c790db
3 changed files with 48 additions and 28 deletions
1
value.cc
1
value.cc
|
|
@ -26,6 +26,7 @@ value_t& value_t::operator=(const value_t& value)
|
||||||
return *this;
|
return *this;
|
||||||
|
|
||||||
destroy();
|
destroy();
|
||||||
|
|
||||||
switch (value.type) {
|
switch (value.type) {
|
||||||
case BOOLEAN:
|
case BOOLEAN:
|
||||||
*((bool *) data) = *((bool *) value.data);
|
*((bool *) data) = *((bool *) value.data);
|
||||||
|
|
|
||||||
39
value.h
39
value.h
|
|
@ -37,7 +37,7 @@ class value_t
|
||||||
type = INTEGER;
|
type = INTEGER;
|
||||||
}
|
}
|
||||||
|
|
||||||
value_t(const value_t& value) {
|
value_t(const value_t& value) : type(INTEGER) {
|
||||||
DEBUG_PRINT("ledger.memory.ctors", "ctor value_t");
|
DEBUG_PRINT("ledger.memory.ctors", "ctor value_t");
|
||||||
*this = value;
|
*this = value;
|
||||||
}
|
}
|
||||||
|
|
@ -51,20 +51,17 @@ class value_t
|
||||||
*((unsigned int *) data) = value;
|
*((unsigned int *) data) = value;
|
||||||
type = INTEGER;
|
type = INTEGER;
|
||||||
}
|
}
|
||||||
value_t(const amount_t& value) {
|
value_t(const amount_t& value) : type(INTEGER) {
|
||||||
DEBUG_PRINT("ledger.memory.ctors", "ctor value_t");
|
DEBUG_PRINT("ledger.memory.ctors", "ctor value_t");
|
||||||
new((amount_t *)data) amount_t(value);
|
*this = value;
|
||||||
type = AMOUNT;
|
|
||||||
}
|
}
|
||||||
value_t(const balance_t& value) {
|
value_t(const balance_t& value) : type(INTEGER) {
|
||||||
DEBUG_PRINT("ledger.memory.ctors", "ctor value_t");
|
DEBUG_PRINT("ledger.memory.ctors", "ctor value_t");
|
||||||
new((balance_t *)data) balance_t(value);
|
*this = value;
|
||||||
type = BALANCE;
|
|
||||||
}
|
}
|
||||||
value_t(const balance_pair_t& value) {
|
value_t(const balance_pair_t& value) : type(INTEGER) {
|
||||||
DEBUG_PRINT("ledger.memory.ctors", "ctor value_t");
|
DEBUG_PRINT("ledger.memory.ctors", "ctor value_t");
|
||||||
new((balance_pair_t *)data) balance_pair_t(value);
|
*this = value;
|
||||||
type = BALANCE_PAIR;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
~value_t() {
|
~value_t() {
|
||||||
|
|
@ -76,33 +73,55 @@ class value_t
|
||||||
|
|
||||||
value_t& operator=(const value_t& value);
|
value_t& operator=(const value_t& value);
|
||||||
value_t& operator=(const bool value) {
|
value_t& operator=(const bool value) {
|
||||||
|
if ((bool *) data != &value) {
|
||||||
destroy();
|
destroy();
|
||||||
*((bool *) data) = value;
|
*((bool *) data) = value;
|
||||||
type = BOOLEAN;
|
type = BOOLEAN;
|
||||||
|
}
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
value_t& operator=(const unsigned int value) {
|
value_t& operator=(const unsigned int value) {
|
||||||
|
if ((unsigned int *) data != &value) {
|
||||||
destroy();
|
destroy();
|
||||||
*((unsigned int *) data) = value;
|
*((unsigned int *) data) = value;
|
||||||
type = INTEGER;
|
type = INTEGER;
|
||||||
|
}
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
value_t& operator=(const amount_t& value) {
|
value_t& operator=(const amount_t& value) {
|
||||||
|
if ((amount_t *) data != &value) {
|
||||||
|
if (! value) {
|
||||||
|
return *this = 0U;
|
||||||
|
} else {
|
||||||
destroy();
|
destroy();
|
||||||
new((amount_t *)data) amount_t(value);
|
new((amount_t *)data) amount_t(value);
|
||||||
type = AMOUNT;
|
type = AMOUNT;
|
||||||
|
}
|
||||||
|
}
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
value_t& operator=(const balance_t& value) {
|
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();
|
destroy();
|
||||||
new((balance_t *)data) balance_t(value);
|
new((balance_t *)data) balance_t(value);
|
||||||
type = BALANCE;
|
type = BALANCE;
|
||||||
|
}
|
||||||
|
}
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
value_t& operator=(const balance_pair_t& value) {
|
value_t& operator=(const balance_pair_t& value) {
|
||||||
|
if ((balance_pair_t *) data != &value) {
|
||||||
|
if (! value.cost) {
|
||||||
|
return *this = value.quantity;
|
||||||
|
} else {
|
||||||
destroy();
|
destroy();
|
||||||
new((balance_pair_t *)data) balance_pair_t(value);
|
new((balance_pair_t *)data) balance_pair_t(value);
|
||||||
type = BALANCE_PAIR;
|
type = BALANCE_PAIR;
|
||||||
|
}
|
||||||
|
}
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
6
walk.h
6
walk.h
|
|
@ -40,6 +40,9 @@ struct item_handler {
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
class compare_items {
|
class compare_items {
|
||||||
|
value_t left_result;
|
||||||
|
value_t right_result;
|
||||||
|
|
||||||
const value_expr_t * sort_order;
|
const value_expr_t * sort_order;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
@ -52,9 +55,6 @@ class compare_items {
|
||||||
assert(left);
|
assert(left);
|
||||||
assert(right);
|
assert(right);
|
||||||
|
|
||||||
value_t left_result;
|
|
||||||
value_t right_result;
|
|
||||||
|
|
||||||
sort_order->compute(left_result, details_t(left));
|
sort_order->compute(left_result, details_t(left));
|
||||||
sort_order->compute(right_result, details_t(right));
|
sort_order->compute(right_result, details_t(right));
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue