From 3c50b2fb7aa1c688379ac26bb7203dd258559517 Mon Sep 17 00:00:00 2001 From: John Wiegley Date: Thu, 26 Aug 2004 15:35:14 -0400 Subject: read all binary data in at one go; gains 33% --- amount.cc | 36 ++++++++++++++++++++++++++++++++++-- 1 file changed, 34 insertions(+), 2 deletions(-) (limited to 'amount.cc') diff --git a/amount.cc b/amount.cc index a99f7d73..b168551b 100644 --- a/amount.cc +++ b/amount.cc @@ -671,7 +671,7 @@ std::ostream& operator<<(std::ostream& _out, const amount_t& amt) std::free(p); } else { - std::list 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::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; -- cgit v1.2.3