1 /*
2     Copyright (C) 2008, 2009 William Hart
3     Copyright (C) 2010 Fredrik Johansson
4 
5     This file is part of FLINT.
6 
7     FLINT is free software: you can redistribute it and/or modify it under
8     the terms of the GNU Lesser General Public License (LGPL) as published
9     by the Free Software Foundation; either version 2.1 of the License, or
10     (at your option) any later version.  See <https://www.gnu.org/licenses/>.
11 */
12 
13 #include <gmp.h>
14 #include "flint.h"
15 #include "fmpz.h"
16 #include "fmpz_vec.h"
17 
18 void
_fmpz_factor_fit_length(fmpz_factor_t factor,slong len)19 _fmpz_factor_fit_length(fmpz_factor_t factor, slong len)
20 {
21     if (len > factor->alloc)
22     {
23         if (len < 2 * factor->alloc)
24             len = 2 * factor->alloc;
25 
26         factor->p = (fmpz *) flint_realloc(factor->p, len * sizeof(fmpz));
27         factor->exp = flint_realloc(factor->exp, len * sizeof(slong));
28 
29         if (len > factor->alloc)
30         {
31             flint_mpn_zero((mp_ptr)(factor->p + factor->alloc), len-factor->alloc);
32             flint_mpn_zero((mp_ptr)(factor->exp + factor->alloc), len-factor->alloc);
33         }
34 
35         factor->alloc = len;
36     }
37 }
38