1 /*
2 Copyright (C) 2011 Sebastian Pancratz
3
4 This file is part of FLINT.
5
6 FLINT is free software: you can redistribute it and/or modify it under
7 the terms of the GNU Lesser General Public License (LGPL) as published
8 by the Free Software Foundation; either version 2.1 of the License, or
9 (at your option) any later version. See <https://www.gnu.org/licenses/>.
10 */
11
12 #include "fmpz_mod_poly.h"
13
fmpz_mod_poly_realloc(fmpz_mod_poly_t poly,slong alloc,const fmpz_mod_ctx_t ctx)14 void fmpz_mod_poly_realloc(fmpz_mod_poly_t poly, slong alloc,
15 const fmpz_mod_ctx_t ctx)
16 {
17 if (alloc == 0) /* Clear up, reinitialise */
18 {
19 if (poly->coeffs)
20 _fmpz_vec_clear(poly->coeffs, poly->alloc);
21
22 poly->coeffs = NULL;
23 poly->length = 0;
24 poly->alloc = 0;
25
26 return;
27 }
28
29 if (poly->alloc) /* Realloc */
30 {
31 fmpz_mod_poly_truncate(poly, alloc, ctx);
32
33 poly->coeffs = (fmpz *) flint_realloc(poly->coeffs, alloc * sizeof(fmpz));
34 if (alloc > poly->alloc)
35 flint_mpn_zero((mp_ptr) (poly->coeffs + poly->alloc),
36 alloc - poly->alloc);
37 }
38 else /* Nothing allocated already so do it now */
39 {
40 poly->coeffs = (fmpz *) flint_calloc(alloc, sizeof(fmpz));
41 }
42
43 poly->alloc = alloc;
44 }
45