performance tweaks
This commit is contained in:
parent
0c8dff61ed
commit
0cac03ba7d
2 changed files with 6 additions and 23 deletions
27
amount.cc
27
amount.cc
|
|
@ -392,13 +392,7 @@ amount_t& amount_t::operator*=(const amount_t& amt)
|
||||||
INIT();
|
INIT();
|
||||||
|
|
||||||
mpz_mul(MPZ(quantity), MPZ(quantity), MPZ(amt.quantity));
|
mpz_mul(MPZ(quantity), MPZ(quantity), MPZ(amt.quantity));
|
||||||
|
mpz_tdiv_q(MPZ(quantity), MPZ(quantity), full_divisor);
|
||||||
// Truncate to the recorded precision: MAX_PRECISION.
|
|
||||||
mpz_t divisor;
|
|
||||||
mpz_init(divisor);
|
|
||||||
mpz_ui_pow_ui(divisor, 10, MAX_PRECISION);
|
|
||||||
mpz_tdiv_q(MPZ(quantity), MPZ(quantity), divisor);
|
|
||||||
mpz_clear(divisor);
|
|
||||||
|
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
@ -410,15 +404,9 @@ amount_t& amount_t::operator/=(const amount_t& amt)
|
||||||
|
|
||||||
INIT();
|
INIT();
|
||||||
|
|
||||||
mpz_t divisor;
|
mpz_mul(MPZ(quantity), MPZ(quantity), full_divisor);
|
||||||
mpz_init(divisor);
|
|
||||||
mpz_ui_pow_ui(divisor, 10, MAX_PRECISION);
|
|
||||||
|
|
||||||
mpz_mul(MPZ(quantity), MPZ(quantity), divisor);
|
|
||||||
mpz_tdiv_q(MPZ(quantity), MPZ(quantity), MPZ(amt.quantity));
|
mpz_tdiv_q(MPZ(quantity), MPZ(quantity), MPZ(amt.quantity));
|
||||||
|
|
||||||
mpz_clear(divisor);
|
|
||||||
|
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -429,15 +417,9 @@ amount_t& amount_t::operator%=(const amount_t& amt)
|
||||||
|
|
||||||
INIT();
|
INIT();
|
||||||
|
|
||||||
mpz_t divisor;
|
mpz_mul(MPZ(quantity), MPZ(quantity), full_divisor);
|
||||||
mpz_init(divisor);
|
|
||||||
mpz_ui_pow_ui(divisor, 10, MAX_PRECISION);
|
|
||||||
|
|
||||||
mpz_mul(MPZ(quantity), MPZ(quantity), divisor);
|
|
||||||
mpz_tdiv_r(MPZ(quantity), MPZ(quantity), MPZ(amt.quantity));
|
mpz_tdiv_r(MPZ(quantity), MPZ(quantity), MPZ(amt.quantity));
|
||||||
|
|
||||||
mpz_clear(divisor);
|
|
||||||
|
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -476,8 +458,7 @@ std::ostream& operator<<(std::ostream& out, const amount_t& amt)
|
||||||
if (amt.commodity->precision != MAX_PRECISION)
|
if (amt.commodity->precision != MAX_PRECISION)
|
||||||
mpz_round(rquotient, MPZ(amt.quantity), amt.commodity->precision);
|
mpz_round(rquotient, MPZ(amt.quantity), amt.commodity->precision);
|
||||||
|
|
||||||
mpz_ui_pow_ui(divisor, 10, MAX_PRECISION);
|
mpz_tdiv_qr(quotient, remainder, rquotient, full_divisor);
|
||||||
mpz_tdiv_qr(quotient, remainder, rquotient, divisor);
|
|
||||||
|
|
||||||
if (mpz_sgn(quotient) < 0 || mpz_sgn(remainder) < 0)
|
if (mpz_sgn(quotient) < 0 || mpz_sgn(remainder) < 0)
|
||||||
negative = true;
|
negative = true;
|
||||||
|
|
|
||||||
|
|
@ -87,6 +87,7 @@ void process_arguments(int argc, char ** argv, const bool anywhere,
|
||||||
}
|
}
|
||||||
else if ((*j).long_opt == *i + 2) {
|
else if ((*j).long_opt == *i + 2) {
|
||||||
process_option(*j, argv[++index]);
|
process_option(*j, argv[++index]);
|
||||||
|
i++;
|
||||||
goto next;
|
goto next;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -105,6 +106,7 @@ void process_arguments(int argc, char ** argv, const bool anywhere,
|
||||||
if ((*i)[1] == (*j).short_opt) {
|
if ((*i)[1] == (*j).short_opt) {
|
||||||
if ((*j).wants_arg) {
|
if ((*j).wants_arg) {
|
||||||
process_option(*j, argv[++index]);
|
process_option(*j, argv[++index]);
|
||||||
|
i++;
|
||||||
goto next;
|
goto next;
|
||||||
} else {
|
} else {
|
||||||
process_option(*j);
|
process_option(*j);
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue