* Evas: Remove allocation/free from the critical path.
authorcedric <cedric@7cbeb6ba-43b4-40fd-8cce-4c39aea84d33>
Mon, 15 Jun 2009 14:34:33 +0000 (14:34 +0000)
committercedric <cedric@7cbeb6ba-43b4-40fd-8cce-4c39aea84d33>
Mon, 15 Jun 2009 14:34:33 +0000 (14:34 +0000)
git-svn-id: svn+ssh://svn.enlightenment.org/var/svn/e/trunk/evas@41048 7cbeb6ba-43b4-40fd-8cce-4c39aea84d33

src/lib/engines/common/evas_scale_smooth.c
src/lib/engines/common/evas_scale_smooth_scaler_down.c

index dcdcff6..cd6c5d6 100644 (file)
@@ -6,19 +6,27 @@
 #include "evas_scale_smooth.h"
 #include "evas_blend_private.h"
 
+#define SCALE_CALC_X_POINTS(P, SW, DW)         \
+  P = alloca((DW + 1) * sizeof (int));         \
+  scale_calc_x_points(P, SW, DW);
 
-static DATA32 **scale_calc_y_points(DATA32 *src, int sw, int sh, int dh);
-static int     *scale_calc_x_points(int sw, int dw);
-static int     *scale_calc_a_points(int s, int d);
+#define SCALE_CALC_Y_POINTS(P, SRC, SW, SH, DH)        \
+  P = alloca((DH + 1) * sizeof (DATA32 *));    \
+  scale_calc_y_points(P, SRC, SW, SH, DH);
 
-static DATA32 **
-scale_calc_y_points(DATA32 *src, int sw, int sh, int dh)
+#define SCALE_CALC_A_POINTS(P, S, D)           \
+  P = alloca(D * sizeof (int));                        \
+  scale_calc_a_points(P, S, D);
+
+static void scale_calc_y_points(DATA32** p, DATA32 *src, int sw, int sh, int dh);
+static void scale_calc_x_points(int *p, int sw, int dw);
+static void scale_calc_a_points(int *p, int s, int d);
+
+static void
+scale_calc_y_points(DATA32** p, DATA32 *src, int sw, int sh, int dh)
 {
-   DATA32 **p;
    int i, val, inc;
 
-   p = malloc((dh + 1) * sizeof(DATA32 *));
-   if (!p) return NULL;
    val = 0;
    inc = (sh << 16) / dh;
    for (i = 0; i < dh; i++)
@@ -27,17 +35,13 @@ scale_calc_y_points(DATA32 *src, int sw, int sh, int dh)
        val += inc;
      }
    p[i] = p[i - 1];
-   return p;
 }
 
-static int *
-scale_calc_x_points(int sw, int dw)
+static void
+scale_calc_x_points(int *p, int sw, int dw)
 {
-   int *p;
    int i, val, inc;
 
-   p = malloc((dw + 1) * sizeof(int));
-   if (!p) return NULL;
    val = 0;
    inc = (sw << 16) / dw;
    for (i = 0; i < dw; i++)
@@ -46,17 +50,13 @@ scale_calc_x_points(int sw, int dw)
        val += inc;
      }
    p[i] = p[i - 1];
-   return p;
 }
 
-static int *
-scale_calc_a_points(int s, int d)
+static void
+scale_calc_a_points(int *p, int s, int d)
 {
-   int *p;
    int i, val, inc;
 
-   p = malloc(d * sizeof(int));
-   if (!p) return NULL;
    if (d >= s)
      {
        val = 0;
@@ -83,7 +83,6 @@ scale_calc_a_points(int s, int d)
          }
      }
 //   sleep(1);
-   return p;
 }
 
 #ifdef BUILD_SCALE_SMOOTH
index 97498b0..859f2f3 100644 (file)
@@ -9,12 +9,10 @@
 
    src_data = src->image.data;
 
-   xpoints = scale_calc_x_points(src_region_w, dst_region_w);
-   ypoints = scale_calc_y_points(src_data, src_w, src_region_h, dst_region_h);
-   xapoints = scale_calc_a_points(src_region_w, dst_region_w);
-   yapoints = scale_calc_a_points(src_region_h, dst_region_h);
-   if ( (!xpoints) || (!ypoints) || (!xapoints) || (!yapoints) )
-       goto done_scale_down;
+   SCALE_CALC_X_POINTS(xpoints, src_region_w, dst_region_w);
+   SCALE_CALC_Y_POINTS(ypoints, src_data, src_w, src_region_h, dst_region_h);
+   SCALE_CALC_A_POINTS(xapoints, src_region_w, dst_region_w);
+   SCALE_CALC_A_POINTS(yapoints, src_region_h, dst_region_h);
 
    /* a scanline buffer */
    buf = alloca(dst_clip_w * sizeof(DATA32));
      {
 #include "evas_scale_smooth_scaler_downx_downy.c"
      }
-
-   done_scale_down:
-   if (xpoints) free(xpoints);
-   if (ypoints) free(ypoints);
-   if (xapoints) free(xapoints);
-   if (yapoints) free(yapoints);
 }