[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Guile-commits] 69/85: take_mpz optimization
From: |
Andy Wingo |
Subject: |
[Guile-commits] 69/85: take_mpz optimization |
Date: |
Thu, 13 Jan 2022 03:40:24 -0500 (EST) |
wingo pushed a commit to branch main
in repository guile.
commit 443d23982856e54ad9367d004403653be787e06a
Author: Andy Wingo <wingo@pobox.com>
AuthorDate: Fri Jan 7 20:28:05 2022 +0100
take_mpz optimization
* libguile/integers.c (take_mpz): Avoid making a bignum if the value is
fixable.
---
libguile/integers.c | 8 ++++++--
1 file changed, 6 insertions(+), 2 deletions(-)
diff --git a/libguile/integers.c b/libguile/integers.c
index 520cc6dbb..c7a6e17f8 100644
--- a/libguile/integers.c
+++ b/libguile/integers.c
@@ -299,9 +299,13 @@ normalize_bignum (struct scm_bignum *z)
static SCM
take_mpz (mpz_ptr mpz)
{
- struct scm_bignum *res = make_bignum_from_mpz (mpz);
+ SCM ret;
+ if (mpz_fits_slong_p (mpz))
+ ret = long_to_scm (mpz_get_si (mpz));
+ else
+ ret = scm_from_bignum (make_bignum_from_mpz (mpz));
mpz_clear (mpz);
- return normalize_bignum (res);
+ return ret;
}
static int
- [Guile-commits] 35/85: Simplify scm_bigprint, (continued)
- [Guile-commits] 35/85: Simplify scm_bigprint, Andy Wingo, 2022/01/13
- [Guile-commits] 34/85: Implement integer-to-string with new integer library, Andy Wingo, 2022/01/13
- [Guile-commits] 36/85: Build scm_integer_p on scm_is_integer, not vice versa, Andy Wingo, 2022/01/13
- [Guile-commits] 37/85: Reimplement = on integer lib, clean up scm_num_eq_p, Andy Wingo, 2022/01/13
- [Guile-commits] 40/85: Simplify implementation of min, max, Andy Wingo, 2022/01/13
- [Guile-commits] 42/85: Simplify scm_difference, use integer lib, Andy Wingo, 2022/01/13
- [Guile-commits] 47/85: Fix scm_integer_to_double_z to always round; clean ups, Andy Wingo, 2022/01/13
- [Guile-commits] 50/85: Reimplement scm_{to,from}_{int32,uint32}, Andy Wingo, 2022/01/13
- [Guile-commits] 67/85: scm_to_ipv6 uses scm_to_mpz, Andy Wingo, 2022/01/13
- [Guile-commits] 68/85: Bignums avoid both custom GMP allocator and finalizers, Andy Wingo, 2022/01/13
- [Guile-commits] 69/85: take_mpz optimization,
Andy Wingo <=
- [Guile-commits] 71/85: Re-rewrite integer-expt in C, Andy Wingo, 2022/01/13
- [Guile-commits] 73/85: Optimize scm_integer_mul_zz., Andy Wingo, 2022/01/13
- [Guile-commits] 84/85: Have log and log10(real nan) return real nan regardless of sign, Andy Wingo, 2022/01/13
- [Guile-commits] 85/85: Remove dead code in scm_integer_inexact_sqrt_z, Andy Wingo, 2022/01/13
- [Guile-commits] 24/85: Implement scm_logtest with new integer library, Andy Wingo, 2022/01/13
- [Guile-commits] 13/85: Implement centered-quotient with new integer lib, Andy Wingo, 2022/01/13
- [Guile-commits] 23/85: Implement scm_logxor with new integer library, Andy Wingo, 2022/01/13
- [Guile-commits] 19/85: Implement gcd with new integer lib, Andy Wingo, 2022/01/13
- [Guile-commits] 57/85: Expose frexp from integers lib, Andy Wingo, 2022/01/13
- [Guile-commits] 59/85: divide2double refactor, Andy Wingo, 2022/01/13