1 /*
2 Copyright (C) 2008, 2009 William Hart
3 Copyright (C) 2012 Andres Goens
4 Copyright (C) 2013 Mike Hansen
5
6 This file is part of FLINT.
7
8 FLINT is free software: you can redistribute it and/or modify it under
9 the terms of the GNU Lesser General Public License (LGPL) as published
10 by the Free Software Foundation; either version 2.1 of the License, or
11 (at your option) any later version. See <http://www.gnu.org/licenses/>.
12 */
13
14 #ifdef T
15
16 #include "templates.h"
17
18 void
TEMPLATE(T,poly_realloc)19 TEMPLATE(T, poly_realloc) (TEMPLATE(T, poly_t) poly, slong alloc,
20 const TEMPLATE(T, ctx_t) ctx)
21 {
22 slong i;
23
24 if (alloc == 0) /* Clear up, reinitialise */
25 {
26 TEMPLATE(T, poly_clear) (poly, ctx);
27 TEMPLATE(T, poly_init) (poly, ctx);
28 }
29 else if (poly->alloc) /* Realloc */
30 {
31 for (i = alloc; i < poly->alloc; i++)
32 TEMPLATE(T, clear) (poly->coeffs + i, ctx);
33
34 poly->coeffs =
35 (TEMPLATE(T, struct) *) flint_realloc(poly->coeffs,
36 alloc *
37 sizeof(TEMPLATE(T, struct)));
38
39 for (i = poly->alloc; i < alloc; i++)
40 TEMPLATE(T, init) (poly->coeffs + i, ctx);
41
42 poly->length = FLINT_MIN(poly->length, alloc);
43 _TEMPLATE(T, poly_normalise) (poly, ctx);
44 }
45 else /* Nothing allocated already so do it now */
46 {
47 poly->coeffs =
48 (TEMPLATE(T, struct) *) flint_malloc(alloc *
49 sizeof(TEMPLATE(T, struct)));
50
51 for (i = 0; i < alloc; i++)
52 TEMPLATE(T, init) (poly->coeffs + i, ctx);
53 }
54 poly->alloc = alloc;
55 }
56
57
58 #endif
59