From d7e6d021615adcd0bf1d6f4d0c52f75ab34a6584 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Tue, 8 Jan 2013 02:20:05 +0000 Subject: simplify fcm_generator_verify() using MEM_recallocN --- source/blender/blenkernel/intern/fmodifier.c | 53 +++++++++------------------- 1 file changed, 16 insertions(+), 37 deletions(-) (limited to 'source/blender/blenkernel/intern/fmodifier.c') diff --git a/source/blender/blenkernel/intern/fmodifier.c b/source/blender/blenkernel/intern/fmodifier.c index 47397a60b20..7b007af86d6 100644 --- a/source/blender/blenkernel/intern/fmodifier.c +++ b/source/blender/blenkernel/intern/fmodifier.c @@ -141,55 +141,34 @@ static void fcm_generator_verify(FModifier *fcm) switch (data->mode) { case FCM_GENERATOR_POLYNOMIAL: /* expanded polynomial expression */ { + const int arraysize_new = data->poly_order + 1; /* arraysize needs to be order+1, so resize if not */ - if (data->arraysize != (data->poly_order + 1)) { - float *nc; - - /* make new coefficients array, and copy over as much data as can fit */ - nc = MEM_callocN(sizeof(float) * (data->poly_order + 1), "FMod_Generator_Coefs"); - + if (data->arraysize != arraysize_new) { if (data->coefficients) { - if ((int)data->arraysize > (data->poly_order + 1)) - memcpy(nc, data->coefficients, sizeof(float) * (data->poly_order + 1)); - else - memcpy(nc, data->coefficients, sizeof(float) * data->arraysize); - - /* free the old data */ - MEM_freeN(data->coefficients); + data->coefficients = MEM_recallocN(data->coefficients, sizeof(float) * arraysize_new); } - - /* set the new data */ - data->coefficients = nc; - data->arraysize = data->poly_order + 1; + else { + data->coefficients = MEM_callocN(sizeof(float) * arraysize_new, "FMod_Generator_Coefs"); + } + data->arraysize = arraysize_new; } + break; } - break; - case FCM_GENERATOR_POLYNOMIAL_FACTORISED: /* expanded polynomial expression */ { + const int arraysize_new = data->poly_order * 2; /* arraysize needs to be (2 * order), so resize if not */ - if (data->arraysize != (data->poly_order * 2)) { - float *nc; - - /* make new coefficients array, and copy over as much data as can fit */ - nc = MEM_callocN(sizeof(float) * (data->poly_order * 2), "FMod_Generator_Coefs"); - + if (data->arraysize != arraysize_new) { if (data->coefficients) { - if (data->arraysize > (unsigned int)(data->poly_order * 2)) - memcpy(nc, data->coefficients, sizeof(float) * (data->poly_order * 2)); - else - memcpy(nc, data->coefficients, sizeof(float) * data->arraysize); - - /* free the old data */ - MEM_freeN(data->coefficients); + data->coefficients = MEM_recallocN(data->coefficients, sizeof(float) * arraysize_new); } - - /* set the new data */ - data->coefficients = nc; - data->arraysize = data->poly_order * 2; + else { + data->coefficients = MEM_callocN(sizeof(float) * arraysize_new, "FMod_Generator_Coefs"); + } + data->arraysize = arraysize_new; } + break; } - break; } } -- cgit v1.2.3