diff options
author | John Wiegley <johnw@newartisans.com> | 2004-08-17 22:18:38 -0400 |
---|---|---|
committer | John Wiegley <johnw@newartisans.com> | 2004-08-17 22:18:38 -0400 |
commit | 55d58940ceb6a47e4032bbad83909d1ca82d2e03 (patch) | |
tree | 3cf5414137af9893924bedc3c6ad8c9f48a8084b /amount.cc | |
parent | 18ec7d05391d55a804042f47882c5af4e5765e86 (diff) | |
download | fork-ledger-55d58940ceb6a47e4032bbad83909d1ca82d2e03.tar.gz fork-ledger-55d58940ceb6a47e4032bbad83909d1ca82d2e03.tar.bz2 fork-ledger-55d58940ceb6a47e4032bbad83909d1ca82d2e03.zip |
speed improvements; my "bal" script is cut to a third
Diffstat (limited to 'amount.cc')
-rw-r--r-- | amount.cc | 92 |
1 files changed, 75 insertions, 17 deletions
@@ -254,16 +254,25 @@ amount_t& amount_t::negate() return *this; } -// comparisons to zero +// integer comparisons +template <typename T> +static inline void parse_num(amount_t& amt, T num) { + std::string str; + { std::ostringstream strstr(str); + strstr << num; + } + { std::istringstream strstr(str); + amt.parse(strstr); + } +} + bool amount_t::operator<(const int num) const { if (num == 0) { return quantity ? mpz_sgn(MPZ(quantity)) < 0 : false; } else { - std::string str; - std::ostringstream strstr(str); - strstr << num; - amount_t amt(strstr.str()); + amount_t amt; + parse_num(amt, num); return *this < amt; } } @@ -273,10 +282,8 @@ bool amount_t::operator<=(const int num) const if (num == 0) { return quantity ? mpz_sgn(MPZ(quantity)) <= 0 : true; } else { - std::string str; - std::ostringstream strstr(str); - strstr << num; - amount_t amt(strstr.str()); + amount_t amt; + parse_num(amt, num); return *this <= amt; } } @@ -286,10 +293,8 @@ bool amount_t::operator>(const int num) const if (num == 0) { return quantity ? mpz_sgn(MPZ(quantity)) > 0 : false; } else { - std::string str; - std::ostringstream strstr(str); - strstr << num; - amount_t amt(strstr.str()); + amount_t amt; + parse_num(amt, num); return *this > amt; } } @@ -299,14 +304,67 @@ bool amount_t::operator>=(const int num) const if (num == 0) { return quantity ? mpz_sgn(MPZ(quantity)) >= 0 : true; } else { - std::string str; - std::ostringstream strstr(str); - strstr << num; - amount_t amt(strstr.str()); + amount_t amt; + parse_num(amt, num); return *this >= amt; } } +bool amount_t::operator<(const unsigned int num) const +{ + if (num == 0) { + return quantity ? mpz_sgn(MPZ(quantity)) < 0 : false; + } else { + amount_t amt; + parse_num(amt, num); + return *this < amt; + } +} + +bool amount_t::operator<=(const unsigned int num) const +{ + if (num == 0) { + return quantity ? mpz_sgn(MPZ(quantity)) <= 0 : true; + } else { + amount_t amt; + parse_num(amt, num); + return *this <= amt; + } +} + +bool amount_t::operator>(const unsigned int num) const +{ + if (num == 0) { + return quantity ? mpz_sgn(MPZ(quantity)) > 0 : false; + } else { + amount_t amt; + parse_num(amt, num); + return *this > amt; + } +} + +bool amount_t::operator>=(const unsigned int num) const +{ + if (num == 0) { + return quantity ? mpz_sgn(MPZ(quantity)) >= 0 : true; + } else { + amount_t amt; + parse_num(amt, num); + return *this >= amt; + } +} + +bool amount_t::operator==(const unsigned int num) const +{ + if (num == 0) { + return quantity ? mpz_sgn(MPZ(quantity)) == 0 : true; + } else { + amount_t amt; + parse_num(amt, num); + return *this == amt; + } +} + // comparisons between amounts bool amount_t::operator<(const amount_t& amt) const { |