From 99f384b4d61dbde135d63fad7f89c3451ec2e4c0 Mon Sep 17 00:00:00 2001 From: Lars-Dominik Braun Date: Sat, 25 Apr 2015 12:17:12 +0200 Subject: Store pointer to array element once Instead of indexing the array over and over --- flam3.c | 65 +++++++++++++++++++++++-------------------- flam3.h | 5 ++-- palettes.c | 2 +- palettes.h | 2 +- variations.c | 90 +++++++++++++++++++++++++++++++----------------------------- 5 files changed, 87 insertions(+), 77 deletions(-) diff --git a/flam3.c b/flam3.c index d491451..389a97c 100644 --- a/flam3.c +++ b/flam3.c @@ -293,7 +293,7 @@ void flam3_interpolate(flam3_genome cps[], int ncps, } -void flam3_copy_params(flam3_xform *dest, flam3_xform *src, int varn) { +void flam3_copy_params(flam3_xform * restrict dest, flam3_xform * restrict src, int varn) { /* We only want to copy param var coefs for this one */ if (varn==VAR_BLOB) { @@ -653,7 +653,8 @@ void flam3_copy(flam3_genome *dest, const flam3_genome * const src) { palette_copy (&src->palette, &dest->palette); } -void flam3_copyx(flam3_genome *dest, flam3_genome *src, int dest_std_xforms, int dest_final_xform) { +void flam3_copyx(flam3_genome * restrict dest, flam3_genome * restrict src, + int dest_std_xforms, int dest_final_xform) { int i,numsrcstd; @@ -691,16 +692,18 @@ void flam3_copyx(flam3_genome *dest, flam3_genome *src, int dest_std_xforms, int if (dest_final_xform > 0) { flam3_add_xforms(dest, dest_final_xform, 1, 1); + flam3_xform * const xf = &dest->xform[dest->num_xforms-1]; + if (src->final_xform_enable > 0) { i = src->final_xform_index; - flam3_copy_xform(&dest->xform[dest->num_xforms-1],&src->xform[i]); + flam3_copy_xform(xf, &src->xform[i]); } else { /* Interpolated-against final xforms need animate & color_speed set to 0.0 */ - dest->xform[dest->num_xforms-1].animate=0.0; - dest->xform[dest->num_xforms-1].color_speed=0.0; + xf->animate=0.0; + xf->color_speed=0.0; } } else { @@ -1401,19 +1404,21 @@ void flam3_add_symmetry(flam3_genome *cp, int sym, randctx * const rc) { flam3_add_xforms(cp,1,0,0); - cp->xform[i].density = 1.0; - cp->xform[i].color_speed = 0.0; - cp->xform[i].animate = 0.0; - cp->xform[i].var[0] = 1.0; + flam3_xform * const xf = &cp->xform[i]; + + xf->density = 1.0; + xf->color_speed = 0.0; + xf->animate = 0.0; + xf->var[0] = 1.0; for (j = 1; j < flam3_nvariations; j++) - cp->xform[i].var[j] = 0; - cp->xform[i].color = 1.0; - cp->xform[i].c[0][0] = -1.0; - cp->xform[i].c[0][1] = 0.0; - cp->xform[i].c[1][0] = 0.0; - cp->xform[i].c[1][1] = 1.0; - cp->xform[i].c[2][0] = 0.0; - cp->xform[i].c[2][1] = 0.0; + xf->var[j] = 0; + xf->color = 1.0; + xf->c[0][0] = -1.0; + xf->c[0][1] = 0.0; + xf->c[1][0] = 0.0; + xf->c[1][1] = 1.0; + xf->c[2][0] = 0.0; + xf->c[2][1] = 0.0; result++; sym = -sym; @@ -1429,19 +1434,21 @@ void flam3_add_symmetry(flam3_genome *cp, int sym, randctx * const rc) { flam3_add_xforms(cp, 1, 0,0); - cp->xform[i].density = 1.0; - cp->xform[i].color_speed = 0.0; - cp->xform[i].animate = 0.0; - cp->xform[i].var[0] = 1.0; + flam3_xform * const xf = &cp->xform[i]; + + xf->density = 1.0; + xf->color_speed = 0.0; + xf->animate = 0.0; + xf->var[0] = 1.0; for (j = 1; j < flam3_nvariations; j++) - cp->xform[i].var[j] = 0; - cp->xform[i].color = (sym<3) ? 0.0 : ((k-1.0)/(sym-2.0)); - cp->xform[i].c[0][0] = round6(cos(k*a)); - cp->xform[i].c[0][1] = round6(sin(k*a)); - cp->xform[i].c[1][0] = round6(-cp->xform[i].c[0][1]); - cp->xform[i].c[1][1] = cp->xform[i].c[0][0]; - cp->xform[i].c[2][0] = 0.0; - cp->xform[i].c[2][1] = 0.0; + xf->var[j] = 0; + xf->color = (sym<3) ? 0.0 : ((k-1.0)/(sym-2.0)); + xf->c[0][0] = round6(cos(k*a)); + xf->c[0][1] = round6(sin(k*a)); + xf->c[1][0] = round6(-cp->xform[i].c[0][1]); + xf->c[1][1] = cp->xform[i].c[0][0]; + xf->c[2][0] = 0.0; + xf->c[2][1] = 0.0; result++; } diff --git a/flam3.h b/flam3.h index 9008f4e..e533833 100644 --- a/flam3.h +++ b/flam3.h @@ -436,8 +436,9 @@ void flam3_add_xforms(flam3_genome *cp, int num_to_add, int interp_padding, int void flam3_delete_xform(flam3_genome *thiscp, int idx_to_delete); void flam3_copy_xform(flam3_xform *dest, flam3_xform *src); void flam3_copy(flam3_genome *dest, const flam3_genome * const src); -void flam3_copyx(flam3_genome *dest, flam3_genome *src, int num_std, int num_final); -void flam3_copy_params(flam3_xform *dest, flam3_xform *src, int varn); +void flam3_copyx(flam3_genome * restrict dest, flam3_genome * restrict src, + int dest_std_xforms, int dest_final_xform); +void flam3_copy_params(flam3_xform * restrict dest, flam3_xform * restrict src, int varn); unsigned short* flam3_create_xform_distrib(flam3_genome *cp); int flam3_create_chaos_distrib(flam3_genome *cp, int xi, unsigned short *xform_distrib); diff --git a/palettes.c b/palettes.c index 92ddc79..1e927e4 100644 --- a/palettes.c +++ b/palettes.c @@ -120,7 +120,7 @@ const palette *palette_random (const palette_collection * const pc, return &pc->p[i]; } -void palette_copy (const palette * const src, palette * const dest) { +void palette_copy (const palette * restrict const src, palette * restrict const dest) { dest->count = src->count; int ret = posix_memalign ((void **) &dest->color, sizeof (*dest->color), sizeof (*dest->color) * dest->count); diff --git a/palettes.h b/palettes.h index 86e4eb1..77620bf 100644 --- a/palettes.h +++ b/palettes.h @@ -45,7 +45,7 @@ double4 hsv2rgb(double4); void palette_add (palette * const p, const double4 c); const palette *palette_random (const palette_collection * const pc, randctx * const rc); -void palette_copy (const palette * const src, palette * const dest); +void palette_copy (const palette * restrict const src, palette * restrict const dest); void palette_rotate_hue (palette * const p, double rot); bool palette_read_collection (const char * const filename, palette_collection * const pc); diff --git a/variations.c b/variations.c index dc6aacf..6b13fd2 100644 --- a/variations.c +++ b/variations.c @@ -1927,7 +1927,9 @@ int prepare_precalc_flags(flam3_genome *cp) { /* Loop over valid xforms */ for (i = 0; i < cp->num_xforms; i++) { - d = cp->xform[i].density; + flam3_xform * const xf = &cp->xform[i]; + + d = xf->density; if (d < 0.0) { fprintf(stderr, "xform %d weight must be non-negative, not %g.\n",i,d); return(1); @@ -1938,94 +1940,94 @@ int prepare_precalc_flags(flam3_genome *cp) { totnum = 0; - cp->xform[i].vis_adjusted = adjust_percentage(cp->xform[i].opacity); + xf->vis_adjusted = adjust_percentage(xf->opacity); - cp->xform[i].precalc_angles_flag=0; - cp->xform[i].precalc_atan_xy_flag=0; - cp->xform[i].precalc_atan_yx_flag=0; - cp->xform[i].has_preblur=0; - cp->xform[i].has_post = !(id_matrix(cp->xform[i].post)); + xf->precalc_angles_flag=0; + xf->precalc_atan_xy_flag=0; + xf->precalc_atan_yx_flag=0; + xf->has_preblur=0; + xf->has_post = !(id_matrix(xf->post)); for (j = 0; j < flam3_nvariations; j++) { - if (cp->xform[i].var[j]!=0) { + if (xf->var[j]!=0) { - cp->xform[i].varFunc[totnum] = j; - cp->xform[i].active_var_weights[totnum] = cp->xform[i].var[j]; + xf->varFunc[totnum] = j; + xf->active_var_weights[totnum] = xf->var[j]; if (j==VAR_POLAR) { - cp->xform[i].precalc_atan_xy_flag=1; + xf->precalc_atan_xy_flag=1; } else if (j==VAR_HANDKERCHIEF) { - cp->xform[i].precalc_atan_xy_flag=1; + xf->precalc_atan_xy_flag=1; } else if (j==VAR_HEART) { - cp->xform[i].precalc_atan_xy_flag=1; + xf->precalc_atan_xy_flag=1; } else if (j==VAR_DISC) { - cp->xform[i].precalc_atan_xy_flag=1; + xf->precalc_atan_xy_flag=1; } else if (j==VAR_SPIRAL) { - cp->xform[i].precalc_angles_flag=1; + xf->precalc_angles_flag=1; } else if (j==VAR_HYPERBOLIC) { - cp->xform[i].precalc_angles_flag=1; + xf->precalc_angles_flag=1; } else if (j==VAR_DIAMOND) { - cp->xform[i].precalc_angles_flag=1; + xf->precalc_angles_flag=1; } else if (j==VAR_EX) { - cp->xform[i].precalc_atan_xy_flag=1; + xf->precalc_atan_xy_flag=1; } else if (j==VAR_JULIA) { - cp->xform[i].precalc_atan_xy_flag=1; + xf->precalc_atan_xy_flag=1; } else if (j==VAR_POWER) { - cp->xform[i].precalc_angles_flag=1; + xf->precalc_angles_flag=1; } else if (j==VAR_RINGS) { - cp->xform[i].precalc_angles_flag=1; + xf->precalc_angles_flag=1; } else if (j==VAR_FAN) { - cp->xform[i].precalc_atan_xy_flag=1; + xf->precalc_atan_xy_flag=1; } else if (j==VAR_BLOB) { - cp->xform[i].precalc_atan_xy_flag=1; - cp->xform[i].precalc_angles_flag=1; + xf->precalc_atan_xy_flag=1; + xf->precalc_angles_flag=1; } else if (j==VAR_FAN2) { - cp->xform[i].precalc_atan_xy_flag=1; + xf->precalc_atan_xy_flag=1; } else if (j==VAR_RINGS2) { - cp->xform[i].precalc_angles_flag=1; + xf->precalc_angles_flag=1; } else if (j==VAR_JULIAN) { - cp->xform[i].precalc_atan_yx_flag=1; + xf->precalc_atan_yx_flag=1; } else if (j==VAR_JULIASCOPE) { - cp->xform[i].precalc_atan_yx_flag=1; + xf->precalc_atan_yx_flag=1; } else if (j==VAR_RADIAL_BLUR) { - cp->xform[i].precalc_atan_yx_flag=1; + xf->precalc_atan_yx_flag=1; } else if (j==VAR_NGON) { - cp->xform[i].precalc_atan_yx_flag=1; + xf->precalc_atan_yx_flag=1; } else if (j==VAR_DISC2) { - cp->xform[i].precalc_atan_xy_flag=1; + xf->precalc_atan_xy_flag=1; } else if (j==VAR_SUPER_SHAPE) { - cp->xform[i].precalc_atan_yx_flag=1; + xf->precalc_atan_yx_flag=1; } else if (j==VAR_FLOWER) { - cp->xform[i].precalc_atan_yx_flag=1; + xf->precalc_atan_yx_flag=1; } else if (j==VAR_CONIC) { - cp->xform[i].precalc_atan_yx_flag=1; + xf->precalc_atan_yx_flag=1; } else if (j==VAR_CPOW) { - cp->xform[i].precalc_atan_yx_flag=1; + xf->precalc_atan_yx_flag=1; } else if (j==VAR_ESCHER) { - cp->xform[i].precalc_atan_yx_flag=1; + xf->precalc_atan_yx_flag=1; } else if (j==VAR_PRE_BLUR) { - cp->xform[i].has_preblur=cp->xform[i].var[j]; + xf->has_preblur=xf->var[j]; } else if (j==VAR_POLAR2) { - cp->xform[i].precalc_atan_xy_flag=1; + xf->precalc_atan_xy_flag=1; } else if (j==VAR_WEDGE) { - cp->xform[i].precalc_atan_yx_flag=1; + xf->precalc_atan_yx_flag=1; } else if (j==VAR_WEDGE_JULIA) { - cp->xform[i].precalc_atan_yx_flag=1; + xf->precalc_atan_yx_flag=1; } else if (j==VAR_WEDGE_SPH) { - cp->xform[i].precalc_atan_yx_flag=1; + xf->precalc_atan_yx_flag=1; } else if (j==VAR_WHORL) { - cp->xform[i].precalc_atan_yx_flag=1; + xf->precalc_atan_yx_flag=1; } else if (j==VAR_LOG) { - cp->xform[i].precalc_atan_yx_flag=1; + xf->precalc_atan_yx_flag=1; } totnum++; } } - cp->xform[i].num_active_vars = totnum; + xf->num_active_vars = totnum; } -- cgit v1.2.3