diff options
author | Campbell Barton <ideasman42@gmail.com> | 2014-04-29 01:50:25 +0400 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2014-04-29 01:50:25 +0400 |
commit | 94e5e2f5d811396f608045ab35f77437290f5759 (patch) | |
tree | e7bcf2707d2bfcb5515bb53a6df00410c1362e71 /source | |
parent | a91c4ac99fd4d766834a42ace4a670dfa824813b (diff) |
Code cleanup: simplify reallocs using MEM_recalloc
Diffstat (limited to 'source')
-rw-r--r-- | source/blender/blenkernel/intern/curve.c | 28 | ||||
-rw-r--r-- | source/blender/makesrna/intern/rna_fcurve.c | 11 |
2 files changed, 10 insertions, 29 deletions
diff --git a/source/blender/blenkernel/intern/curve.c b/source/blender/blenkernel/intern/curve.c index 30638a14b8a..bf4e43944a4 100644 --- a/source/blender/blenkernel/intern/curve.c +++ b/source/blender/blenkernel/intern/curve.c @@ -701,19 +701,13 @@ void BKE_nurb_minmax(Nurb *nu, bool use_radius, float min[3], float max[3]) /* be sure to call makeknots after this */ void BKE_nurb_points_add(Nurb *nu, int number) { - BPoint *tmp = nu->bp; + BPoint *bp; int i; - nu->bp = (BPoint *)MEM_mallocN((nu->pntsu + number) * sizeof(BPoint), "rna_Curve_spline_points_add"); - - if (tmp) { - memmove(nu->bp, tmp, nu->pntsu * sizeof(BPoint)); - MEM_freeN(tmp); - } - memset(nu->bp + nu->pntsu, 0, number * sizeof(BPoint)); + nu->bp = MEM_recallocN(nu->bp, (nu->pntsu + number) * sizeof(BPoint)); - for (i = 0, tmp = nu->bp + nu->pntsu; i < number; i++, tmp++) { - tmp->radius = 1.0f; + for (i = 0, bp = &nu->bp[nu->pntsu]; i < number; i++, bp++) { + bp->radius = 1.0f; } nu->pntsu += number; @@ -721,19 +715,13 @@ void BKE_nurb_points_add(Nurb *nu, int number) void BKE_nurb_bezierPoints_add(Nurb *nu, int number) { - BezTriple *tmp = nu->bezt; + BezTriple *bezt; int i; - nu->bezt = (BezTriple *)MEM_mallocN((nu->pntsu + number) * sizeof(BezTriple), "rna_Curve_spline_points_add"); - - if (tmp) { - memmove(nu->bezt, tmp, nu->pntsu * sizeof(BezTriple)); - MEM_freeN(tmp); - } - memset(nu->bezt + nu->pntsu, 0, number * sizeof(BezTriple)); + nu->bezt = MEM_recallocN(nu->bp, (nu->pntsu + number) * sizeof(BezTriple)); - for (i = 0, tmp = nu->bezt + nu->pntsu; i < number; i++, tmp++) { - tmp->radius = 1.0f; + for (i = 0, bezt = &nu->bezt[nu->pntsu]; i < number; i++, bezt++) { + bezt->radius = 1.0f; } nu->pntsu += number; diff --git a/source/blender/makesrna/intern/rna_fcurve.c b/source/blender/makesrna/intern/rna_fcurve.c index 00caa3ba711..0c5c68e4588 100644 --- a/source/blender/makesrna/intern/rna_fcurve.c +++ b/source/blender/makesrna/intern/rna_fcurve.c @@ -746,15 +746,8 @@ static void rna_FKeyframe_points_add(FCurve *fcu, int tot) { if (tot > 0) { BezTriple *bezt; - if (fcu->totvert) { - BezTriple *nbezt = MEM_callocN(sizeof(BezTriple) * (fcu->totvert + tot), "rna_FKeyframe_points_add"); - memcpy(nbezt, fcu->bezt, sizeof(BezTriple) * fcu->totvert); - MEM_freeN(fcu->bezt); - fcu->bezt = nbezt; - } - else { - fcu->bezt = MEM_callocN(sizeof(BezTriple) * tot, "rna_FKeyframe_points_add"); - } + + fcu->bezt = MEM_recallocN(fcu->bezt, sizeof(BezTriple) * (fcu->totvert + tot)); bezt = fcu->bezt + fcu->totvert; fcu->totvert += tot; |