diff options
author | Andy Wingo <wingo@pobox.com> | 2022-01-07 20:28:05 +0100 |
---|---|---|
committer | Andy Wingo <wingo@pobox.com> | 2022-01-13 09:37:17 +0100 |
commit | 443d23982856e54ad9367d004403653be787e06a (patch) | |
tree | 536d8462d9fa6d281b6d93e25b9bfad43813ea02 /libguile/integers.c | |
parent | aa5455ea98a7f1a65484e08aecbd36426946793f (diff) | |
download | guile-443d23982856e54ad9367d004403653be787e06a.tar.gz |
take_mpz optimization
* libguile/integers.c (take_mpz): Avoid making a bignum if the value is
fixable.
Diffstat (limited to 'libguile/integers.c')
-rw-r--r-- | libguile/integers.c | 8 |
1 files 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 |