diff options
author | John Wiegley <johnw@newartisans.com> | 2004-08-21 03:23:17 -0400 |
---|---|---|
committer | John Wiegley <johnw@newartisans.com> | 2004-08-21 03:23:17 -0400 |
commit | fb91d6f21e341f12d80e95195322837cbda78cf3 (patch) | |
tree | 957c901ee876bae7c174a003b7d552c34776d135 /amount.h | |
parent | 06ac87ab208210bef6a30cf71e116847080d2383 (diff) | |
download | fork-ledger-fb91d6f21e341f12d80e95195322837cbda78cf3.tar.gz fork-ledger-fb91d6f21e341f12d80e95195322837cbda78cf3.tar.bz2 fork-ledger-fb91d6f21e341f12d80e95195322837cbda78cf3.zip |
add copy-on-write semantics to amount.cc; cuts object creation by 5x
Diffstat (limited to 'amount.h')
-rw-r--r-- | amount.h | 27 |
1 files changed, 18 insertions, 9 deletions
@@ -13,15 +13,24 @@ class commodity_t; class amount_t { - typedef void * base_type; - void _init(); void _copy(const amount_t& amt); - void _clear(); + void _release(); + void _dup(); void _resize(int prec); + void _clear() { + if (quantity) + _release(); + quantity = NULL; + commodity = NULL; + precision = 0; + } + public: - base_type quantity; // amount, to MAX_PRECISION + struct bigint_t; + + bigint_t * quantity; // amount, to MAX_PRECISION unsigned short precision; commodity_t * commodity; @@ -40,14 +49,14 @@ class amount_t if (amt.quantity) { _copy(amt); } else { - commodity = amt.commodity; - precision = amt.precision; + precision = 0; + commodity = NULL; } } - amount_t(const std::string& value) { + amount_t(const std::string& value) : quantity(NULL) { parse(value); } - amount_t(const char * value) { + amount_t(const char * value) : quantity(NULL) { parse(value); } amount_t(const bool value); @@ -58,7 +67,7 @@ class amount_t // destructor ~amount_t() { if (quantity) - _clear(); + _release(); } // assignment operator |