diff options
author | John Wiegley <johnw@newartisans.com> | 2004-08-26 15:35:14 -0400 |
---|---|---|
committer | John Wiegley <johnw@newartisans.com> | 2004-08-26 15:35:14 -0400 |
commit | 3c50b2fb7aa1c688379ac26bb7203dd258559517 (patch) | |
tree | fe2f0d8ebfffe7b1c50212c39fbb7b9067895352 /amount.cc | |
parent | 942943323ea1cef85b08935c98fb84b378519d3e (diff) | |
download | fork-ledger-3c50b2fb7aa1c688379ac26bb7203dd258559517.tar.gz fork-ledger-3c50b2fb7aa1c688379ac26bb7203dd258559517.tar.bz2 fork-ledger-3c50b2fb7aa1c688379ac26bb7203dd258559517.zip |
read all binary data in at one go; gains 33%
Diffstat (limited to 'amount.cc')
-rw-r--r-- | amount.cc | 36 |
1 files changed, 34 insertions, 2 deletions
@@ -671,7 +671,7 @@ std::ostream& operator<<(std::ostream& _out, const amount_t& amt) std::free(p); } else { - std::list<std::string> strs; + strings_list strs; char buf[4]; for (int powers = 0; true; powers += 3) { @@ -690,7 +690,7 @@ std::ostream& operator<<(std::ostream& _out, const amount_t& amt) bool printed = false; - for (std::list<std::string>::reverse_iterator i = strs.rbegin(); + for (strings_list::reverse_iterator i = strs.rbegin(); i != strs.rend(); i++) { if (printed) { @@ -904,6 +904,38 @@ void amount_t::write_quantity(std::ostream& out) const } } +void amount_t::read_quantity(char *& data) +{ + char byte = *data++;; + + if (byte == 0) { + quantity = NULL; + } + else if (byte == 1) { + quantity = new(bigints_next++) bigint_t; + quantity->flags |= BIGINT_BULK_ALLOC; + + unsigned short len = *((unsigned short *) data); + data += sizeof(unsigned short); + mpz_import(MPZ(quantity), len / sizeof(short), 1, sizeof(short), + 0, 0, data); + data += len; + + char negative = *data++; + if (negative) + mpz_neg(MPZ(quantity), MPZ(quantity)); + + quantity->prec = *((unsigned short *) data); + data += sizeof(unsigned short); + } else { + unsigned int index = *((unsigned int *) data); + data += sizeof(unsigned int); + + quantity = bigints + (index - 1); + quantity->ref++; + } +} + void amount_t::read_quantity(std::istream& in) { char byte; |