py/mpz: In mpz_clone, remove unused check for NULL dig.
This path for src->deg==NULL is never used because mpz_clone() is always called with an argument that has a non-zero integer value, and hence has some digits allocated to it (mpz_clone() is a static function private to mpz.c all callers of this function first check if the integer value is zero and if so take a special-case path, bypassing the call to mpz_clone()). There is some unused and commented-out functions that may actually pass a zero-valued mpz to mpz_clone(), so some TODOs are added to these function in case they are needed in the future.
This commit is contained in:
parent
77a62d8b5a
commit
f75c7ad1a9
12
py/mpz.c
12
py/mpz.c
@ -705,17 +705,14 @@ STATIC void mpz_need_dig(mpz_t *z, size_t need) {
|
||||
}
|
||||
|
||||
STATIC mpz_t *mpz_clone(const mpz_t *src) {
|
||||
assert(src->alloc != 0);
|
||||
mpz_t *z = m_new_obj(mpz_t);
|
||||
z->neg = src->neg;
|
||||
z->fixed_dig = 0;
|
||||
z->alloc = src->alloc;
|
||||
z->len = src->len;
|
||||
if (src->dig == NULL) {
|
||||
z->dig = NULL;
|
||||
} else {
|
||||
z->dig = m_new(mpz_dig_t, z->alloc);
|
||||
memcpy(z->dig, src->dig, src->alloc * sizeof(mpz_dig_t));
|
||||
}
|
||||
z->dig = m_new(mpz_dig_t, z->alloc);
|
||||
memcpy(z->dig, src->dig, src->alloc * sizeof(mpz_dig_t));
|
||||
return z;
|
||||
}
|
||||
|
||||
@ -983,6 +980,7 @@ these functions are unused
|
||||
/* returns abs(z)
|
||||
*/
|
||||
mpz_t *mpz_abs(const mpz_t *z) {
|
||||
// TODO: handle case of z->alloc=0
|
||||
mpz_t *z2 = mpz_clone(z);
|
||||
z2->neg = 0;
|
||||
return z2;
|
||||
@ -991,6 +989,7 @@ mpz_t *mpz_abs(const mpz_t *z) {
|
||||
/* returns -z
|
||||
*/
|
||||
mpz_t *mpz_neg(const mpz_t *z) {
|
||||
// TODO: handle case of z->alloc=0
|
||||
mpz_t *z2 = mpz_clone(z);
|
||||
z2->neg = 1 - z2->neg;
|
||||
return z2;
|
||||
@ -1408,6 +1407,7 @@ these functions are unused
|
||||
*/
|
||||
mpz_t *mpz_gcd(const mpz_t *z1, const mpz_t *z2) {
|
||||
if (z1->len == 0) {
|
||||
// TODO: handle case of z2->alloc=0
|
||||
mpz_t *a = mpz_clone(z2);
|
||||
a->neg = 0;
|
||||
return a;
|
||||
|
Loading…
Reference in New Issue
Block a user