1
Fork 0
mirror of https://git.savannah.gnu.org/git/guile.git synced 2025-05-20 11:40:18 +02:00

take_mpz optimization

* libguile/integers.c (take_mpz): Avoid making a bignum if the value is
fixable.
This commit is contained in:
Andy Wingo 2022-01-07 20:28:05 +01:00
parent aa5455ea98
commit 443d239828

View file

@ -299,9 +299,13 @@ normalize_bignum (struct scm_bignum *z)
static SCM static SCM
take_mpz (mpz_ptr mpz) 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); mpz_clear (mpz);
return normalize_bignum (res); return ret;
} }
static int static int