diff options
author | Marco Bodrato <bodrato@mail.dm.unipi.it> | 2016-11-09 23:07:54 +0100 |
---|---|---|
committer | Marco Bodrato <bodrato@mail.dm.unipi.it> | 2016-11-09 23:07:54 +0100 |
commit | 6a2dfd953cdb8d2065751538d72179c10c98c9e3 (patch) | |
tree | b97f59df1fc8f285ed61cc4f40c1f90254129b57 /mpz | |
parent | e6a4ed98704dea7a74d445fe256d34a91af97372 (diff) | |
download | gmp-6a2dfd953cdb8d2065751538d72179c10c98c9e3.tar.gz |
mpz/iset_str.c: Lazy allocation
Diffstat (limited to 'mpz')
-rw-r--r-- | mpz/iset_str.c | 5 | ||||
-rw-r--r-- | mpz/set_str.c | 2 |
2 files changed, 4 insertions, 3 deletions
diff --git a/mpz/iset_str.c b/mpz/iset_str.c index d0bf81132..2df12f9a0 100644 --- a/mpz/iset_str.c +++ b/mpz/iset_str.c @@ -36,8 +36,9 @@ see https://www.gnu.org/licenses/. */ int mpz_init_set_str (mpz_ptr x, const char *str, int base) { - ALLOC (x) = 1; - PTR (x) = __GMP_ALLOCATE_FUNC_LIMBS (1); + static const mp_limb_t dummy_limb=0xc1a0; + ALLOC (x) = 0; + PTR (x) = (mp_ptr) &dummy_limb; /* if str has no digits mpz_set_str leaves x->_mp_size unset */ SIZ (x) = 0; diff --git a/mpz/set_str.c b/mpz/set_str.c index 546c66fcc..25b0c32bc 100644 --- a/mpz/set_str.c +++ b/mpz/set_str.c @@ -133,7 +133,7 @@ mpz_set_str (mpz_ptr x, const char *str, int base) str_size = s - begs; LIMBS_PER_DIGIT_IN_BASE (xsize, str_size, base); - MPZ_REALLOC (x, xsize); + MPZ_NEWALLOC (x, xsize); /* Convert the byte array in base BASE to our bignum format. */ xsize = mpn_set_str (PTR (x), (unsigned char *) begs, str_size, base); |