From ec6a3e80814f799d7fc0b416499bea7ac0a8cb5e Mon Sep 17 00:00:00 2001 From: John Wiegley Date: Sat, 31 Jan 2009 05:00:49 -0400 Subject: [PATCH] Made amount_t::is_zero() slightly more efficient. --- src/amount.cc | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/amount.cc b/src/amount.cc index bc8b0b6f..36539232 100644 --- a/src/amount.cc +++ b/src/amount.cc @@ -625,7 +625,18 @@ bool amount_t::is_zero() const if (has_commodity()) { if (keep_precision() || quantity->prec <= commodity().precision()) { return is_realzero(); - } else { + } + else if (is_realzero()) { + return true; + } + else if (mpz_cmp(mpq_numref(MP(quantity)), + mpq_denref(MP(quantity))) > 0) { + DEBUG("amount.is_zero", "Numerator is larger than the denominator"); + return false; + } + else { + DEBUG("amount.is_zero", "We have to print the number to check for zero"); + std::ostringstream out; stream_out_mpq(out, MP(quantity), commodity().precision());