From fa38d10ee461b6589976e8ab97a81b7554be8f7e Mon Sep 17 00:00:00 2001 From: Juan Jose Garcia Ripoll Date: Sun, 1 Jan 2012 20:18:45 +0100 Subject: [PATCH] Simplified _ecl_get_fixnum/index under the assumption that input arguments will never include the zero fixnum. --- src/c/big.d | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/src/c/big.d b/src/c/big.d index 7c84ceeb3..980b3e101 100644 --- a/src/c/big.d +++ b/src/c/big.d @@ -364,28 +364,24 @@ _ecl_big_set_index(cl_object x, cl_index f) cl_fixnum _ecl_big_get_fixnum(cl_object x) { - if (x->big.big_size == 0) { - return 0; - } else { - cl_fixnum n = x->big.big_limbs[0]; - return (x->big.big_size > 0) ? n : -n; - } + /* INV: x is a bignum and thus size != 0 */ + cl_fixnum output = x->big.big_limbs[0]; + return (x->big.big_size > 0) ? output : -output; } cl_index _ecl_big_get_index(cl_object x) { - if (x->big.big_size == 0) { - return 0; - } else { - return (cl_index)x->big.big_limbs[0]; - } + /* INV: x is a bignum and thus size != 0 */ + cl_index output = x->big.big_limbs[0]; + return (x->big.big_size > 0)? output : ~(output - 1); } bool _ecl_big_fits_in_index(cl_object x) { - return (x->big.big_size & (~1)) == 0; + /* INV: x is a bignum and thus size != 0 */ + return (x->big.big_size ^ 1) == 0; } #else # error "ECL cannot build with GMP when both long and mp_limb_t are smaller than cl_fixnum"