Removed some unnecessary variables.

This commit is contained in:
John Wiegley 2007-05-06 10:29:12 +00:00
parent b95aa8d4ca
commit 7868a53b70
3 changed files with 155 additions and 143 deletions

View file

@ -56,18 +56,28 @@ bool amount_t::keep_tag = false;
bool amount_t::full_strings = false;
#ifndef THREADSAFE
/**
* These global temporaries are pre-initialized for the sake of
* efficiency, and reused over and over again.
*/
static mpz_t temp;
static mpz_t divisor;
#endif
struct amount_t::bigint_t
{
#define BIGINT_BULK_ALLOC 0x01
#define BIGINT_KEEP_PREC 0x02
class amount_t::bigint_t
{
public:
mpz_t val;
precision_t prec;
flags_t flags;
uint_least16_t ref;
uint_fast32_t index;
#define MPZ(bigint) ((bigint)->val)
bigint_t() : prec(0), flags(0), ref(1), index(0) {
TRACE_CTOR(bigint_t, "");
mpz_init(val);
@ -82,21 +92,12 @@ class amount_t::bigint_t
TRACE_CTOR(bigint_t, "copy");
mpz_init_set(val, other.val);
}
~bigint_t();
};
#define MPZ(x) ((x)->val)
#ifndef THREADSAFE
static mpz_t temp; // these are the global temp variables
static mpz_t divisor;
#endif
inline amount_t::bigint_t::~bigint_t() {
~bigint_t() {
TRACE_DTOR(bigint_t);
assert(ref == 0);
mpz_clear(val);
}
}
};
void amount_t::initialize()
{
@ -582,6 +583,11 @@ amount_t& amount_t::operator/=(const amount_t& amt)
}
amount_t::precision_t amount_t::precision() const
{
return quantity->prec;
}
amount_t& amount_t::in_place_negate()
{
if (quantity) {
@ -805,8 +811,9 @@ annotation_t amount_t::annotation_details() const
return annotation_t();
}
static void parse_quantity(std::istream& in, string& value)
{
namespace {
void parse_quantity(std::istream& in, string& value)
{
char buf[256];
char c = peek_next_nonws(in);
READ_INTO(in, buf, 255, c,
@ -819,35 +826,35 @@ static void parse_quantity(std::istream& in, string& value)
}
value = buf;
}
}
// Invalid commodity characters:
// SPACE, TAB, NEWLINE, RETURN
// 0-9 . , ; - + * / ^ ? : & | ! =
// < > { } [ ] ( ) @
// Invalid commodity characters:
// SPACE, TAB, NEWL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0, 0, 0, 0, 0, 1, 1, 0, 0, 1, 0, 0,
/* 10 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
/* 20 */ 1, 1, 0, 0, 0, 0, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1,
/* 30 */ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
/* 40 */ 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
/* 50 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 1, 0,
/* 60 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
/* 70 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 1, 0,
/* 80 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
/* 90 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
/* a0 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
/* b0 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
/* c0 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
/* d0 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
/* e0 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
/* f0 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
};
static void parse_commodity(std::istream& in, string& symbol)
{
static void parse_commodity(std::istream& in, string& symbol)
{
char buf[256];
char c = peek_next_nonws(in);
if (c == '"') {
@ -861,10 +868,10 @@ static void parse_commodity(std::istream& in, string& symbol)
READ_INTO(in, buf, 255, c, ! invalid_chars[(unsigned char)c]);
}
symbol = buf;
}
}
bool parse_annotations(std::istream& in, annotation_t& details)
{
bool parse_annotations(std::istream& in, annotation_t& details)
{
do {
char buf[256];
char c = peek_next_nonws(in);
@ -888,7 +895,7 @@ bool parse_annotations(std::istream& in, annotation_t& details)
// may have only specified {$1} or something similar.
if (temp.has_commodity() &&
temp.quantity->prec < temp.commodity().precision())
temp.precision() < temp.commodity().precision())
temp = temp.round(); // no need to retain individual precision
details.price = temp;
@ -934,6 +941,7 @@ bool parse_annotations(std::istream& in, annotation_t& details)
<< (details.tag ? *details.tag : "NONE"));
return details;
}
}
void amount_t::parse(std::istream& in, flags_t flags)

View file

@ -148,7 +148,7 @@ protected:
void _clear();
void _release();
class bigint_t;
struct bigint_t;
bigint_t * quantity;
commodity_t * commodity_;
@ -278,6 +278,11 @@ public:
* Unary arithmetic operators. There are several unary methods
* support on amounts:
*
* precision() return an amount's current, internal precision. To
* find the precision it will be displayed at -- assuming it was not
* created using the static method `amount_t::exact' -- refer to
* commodity().precision.
*
* negate(), also unary minus (- x), returns the negated value of an
* amount.
*
@ -318,6 +323,8 @@ public:
* in_place_reduce()
* in_place_unreduce()
*/
precision_t precision() const;
amount_t negate() const {
amount_t temp = *this;
temp.in_place_negate();
@ -624,9 +631,6 @@ public:
}
bool valid() const;
private:
friend bool parse_annotations(std::istream& in, annotation_t& details);
};
inline amount_t amount_t::exact(const string& value) {