evas -> use mempool for many objects and things. but.. disable it for
authorraster <raster@7cbeb6ba-43b4-40fd-8cce-4c39aea84d33>
Fri, 26 Nov 2010 10:01:18 +0000 (10:01 +0000)
committerraster <raster@7cbeb6ba-43b4-40fd-8cce-4c39aea84d33>
Fri, 26 Nov 2010 10:01:18 +0000 (10:01 +0000)
now. use old calloc+free thing for 1.0 and enable mpool for 1.1. this
is just done in advance but disabled for some testing purposes looking
for some bugs.

git-svn-id: http://svn.enlightenment.org/svn/e/trunk/evas@55006 7cbeb6ba-43b4-40fd-8cce-4c39aea84d33

src/lib/canvas/evas_callbacks.c
src/lib/canvas/evas_object_image.c
src/lib/canvas/evas_object_line.c
src/lib/canvas/evas_object_main.c
src/lib/canvas/evas_object_polygon.c
src/lib/canvas/evas_object_rectangle.c
src/lib/canvas/evas_object_smart.c
src/lib/canvas/evas_object_smart_clipped.c
src/lib/canvas/evas_object_text.c
src/lib/canvas/evas_object_textblock.c
src/lib/include/evas_private.h

index 9570862..b45f051 100644 (file)
@@ -5,6 +5,10 @@ static void evas_object_event_callback_clear(Evas_Object *obj);
 static void evas_event_callback_clear(Evas *e);
 int _evas_event_counter = 0;
 
+EVAS_MEMPOOL(_mp_fn);
+EVAS_MEMPOOL(_mp_cb);
+EVAS_MEMPOOL(_mp_pc);
+
 void
 _evas_post_event_callback_call(Evas *e)
 {
@@ -19,7 +23,7 @@ _evas_post_event_callback_call(Evas *e)
           {
              if (!pc->func((void*)pc->data, e)) skip = 1;
           }
-        free(pc);
+       EVAS_MEMPOOL_FREE(_mp_pc, pc);
      }
    _evas_unwalk(e);
 }
@@ -31,7 +35,7 @@ _evas_post_event_callback_free(Evas *e)
    
    EINA_LIST_FREE(e->post_events, pc)
      {
-        free(pc);
+       EVAS_MEMPOOL_FREE(_mp_pc, pc);
      }
    _evas_unwalk(e);
 }
@@ -51,7 +55,7 @@ evas_event_callback_list_post_free(Eina_Inlist **list)
        if (fn->delete_me)
          {
              *list = eina_inlist_remove(*list, EINA_INLIST_GET(fn));
-            free(fn);
+             EVAS_MEMPOOL_FREE(_mp_fn, fn);
          }
      }
 }
@@ -65,7 +69,7 @@ evas_object_event_callback_clear(Evas_Object *obj)
    evas_event_callback_list_post_free(&obj->callbacks->callbacks);
    if (!obj->callbacks->callbacks)
      {
-        free(obj->callbacks);
+        EVAS_MEMPOOL_FREE(_mp_cb, obj->callbacks);
        obj->callbacks = NULL;
      }
 }
@@ -79,7 +83,7 @@ evas_event_callback_clear(Evas *e)
    evas_event_callback_list_post_free(&e->callbacks->callbacks);
    if (!e->callbacks->callbacks)
      {
-        free(e->callbacks);
+        EVAS_MEMPOOL_FREE(_mp_cb, e->callbacks);
        e->callbacks = NULL;
      }
 }
@@ -100,7 +104,7 @@ evas_object_event_callback_cleanup(Evas_Object *obj)
    /* MEM OK */
    if (!obj->callbacks) return;
    evas_event_callback_list_post_free(&obj->callbacks->callbacks);
-   free(obj->callbacks);
+   EVAS_MEMPOOL_FREE(_mp_cb, obj->callbacks);
    obj->callbacks = NULL;
 }
 
@@ -120,7 +124,7 @@ evas_event_callback_cleanup(Evas *e)
    /* MEM OK */
    if (!e->callbacks) return;
    evas_event_callback_list_post_free(&e->callbacks->callbacks);
-   free(e->callbacks);
+   EVAS_MEMPOOL_FREE(_mp_cb, e->callbacks);
    e->callbacks = NULL;
 }
 
@@ -440,19 +444,22 @@ evas_object_event_callback_add(Evas_Object *obj, Evas_Callback_Type type, Evas_O
 
    if (!func) return;
 
-   fn = evas_mem_calloc(sizeof(Evas_Func_Node));
+   if (!obj->callbacks)
+     {
+        EVAS_MEMPOOL_INIT(_mp_cb, "evas_callbacks", Evas_Callbacks, 512, );
+        obj->callbacks = EVAS_MEMPOOL_ALLOC(_mp_cb, Evas_Callbacks);
+        if (!obj->callbacks) return;
+        EVAS_MEMPOOL_PREP(_mp_cb, obj->callbacks, Evas_Callbacks);
+     }
+  
+   EVAS_MEMPOOL_INIT(_mp_fn, "evas_func_node", Evas_Func_Node, 2048, );
+   fn = EVAS_MEMPOOL_ALLOC(_mp_fn, Evas_Func_Node);
    if (!fn) return;
+   EVAS_MEMPOOL_PREP(_mp_fn, fn, Evas_Func_Node);
    fn->func = func;
    fn->data = (void *)data;
    fn->type = type;
 
-   if (!obj->callbacks)
-     obj->callbacks = evas_mem_calloc(sizeof(Evas_Callbacks));
-   if (!obj->callbacks)
-     {
-       free(fn);
-       return;
-     }
    obj->callbacks->callbacks =
      eina_inlist_prepend(obj->callbacks->callbacks, EINA_INLIST_GET(fn));
 }
@@ -648,19 +655,22 @@ evas_event_callback_add(Evas *e, Evas_Callback_Type type, Evas_Event_Cb func, co
 
    if (!func) return;
 
-   fn = evas_mem_calloc(sizeof(Evas_Func_Node));
+   if (!e->callbacks)
+     {
+        EVAS_MEMPOOL_INIT(_mp_cb, "evas_callbacks", Evas_Callbacks, 512, );
+        e->callbacks = EVAS_MEMPOOL_ALLOC(_mp_cb, Evas_Callbacks);
+        if (!e->callbacks) return;
+        EVAS_MEMPOOL_PREP(_mp_cb, e->callbacks, Evas_Callbacks);
+     }
+  
+   EVAS_MEMPOOL_INIT(_mp_fn, "evas_func_node", Evas_Func_Node, 2048, );
+   fn = EVAS_MEMPOOL_ALLOC(_mp_fn, Evas_Func_Node);
    if (!fn) return;
+   EVAS_MEMPOOL_PREP(_mp_fn, fn, Evas_Func_Node);
    fn->func = func;
    fn->data = (void *)data;
    fn->type = type;
 
-   if (!e->callbacks)
-     e->callbacks = evas_mem_calloc(sizeof(Evas_Callbacks));
-   if (!e->callbacks)
-     {
-       free(fn);
-       return;
-     }
    e->callbacks->callbacks =
      eina_inlist_prepend(e->callbacks->callbacks, EINA_INLIST_GET(fn));
 }
@@ -809,8 +819,10 @@ evas_post_event_callback_push(Evas *e, Evas_Object_Event_Post_Cb func, const voi
    return;
    MAGIC_CHECK_END();
    
-   pc = evas_mem_calloc(sizeof(Evas_Post_Callback));
+   EVAS_MEMPOOL_INIT(_mp_pc, "evas_post_callback", Evas_Post_Callback, 64, );
+   pc = EVAS_MEMPOOL_ALLOC(_mp_pc, Evas_Post_Callback);
    if (!pc) return;
+   EVAS_MEMPOOL_PREP(_mp_pc, pc, Evas_Post_Callback);
    if (e->delete_me) return;
    
    pc->func = func;
index c58ca16..b5dcfd5 100644 (file)
@@ -123,6 +123,8 @@ static const Evas_Object_Func object_func =
  * @{
  */
 
+EVAS_MEMPOOL(_mp_obj);
+
 /**
  * Creates a new image object on the given evas.
  *
@@ -2344,7 +2346,10 @@ evas_object_image_new(void)
    Evas_Object_Image *o;
 
    /* alloc obj private data */
-   o = calloc(1, sizeof(Evas_Object_Image));
+   EVAS_MEMPOOL_INIT(_mp_obj, "evas_object_image", Evas_Object_Image, 256, NULL);
+   o = EVAS_MEMPOOL_ALLOC(_mp_obj, Evas_Object_Image);
+   if (!o) return NULL;
+   EVAS_MEMPOOL_PREP(_mp_obj, o, Evas_Object_Image);
    o->magic = MAGIC_OBJ_IMAGE;
    o->cur.fill.w = 0;
    o->cur.fill.h = 0;
@@ -2384,7 +2389,7 @@ evas_object_image_free(Evas_Object *obj)
    o->magic = 0;
    EINA_LIST_FREE(o->pixel_updates, r)
      eina_rectangle_free(r);
-   free(o);
+   EVAS_MEMPOOL_FREE(_mp_obj, o);
 }
 
 static void
index 6eac374..0baab9e 100644 (file)
@@ -78,6 +78,8 @@ static const Evas_Object_Func object_func =
  * @{
  */
 
+EVAS_MEMPOOL(_mp_obj);
+
 /**
  * Adds a new evas line object to the given evas.
  * @param   e The given evas.
@@ -253,7 +255,10 @@ evas_object_line_new(void)
    Evas_Object_Line *o;
 
    /* alloc obj private data */
-   o = calloc(1, sizeof(Evas_Object_Line));
+   EVAS_MEMPOOL_INIT(_mp_obj, "evas_object_line", Evas_Object_Line, 16, NULL);
+   o = EVAS_MEMPOOL_ALLOC(_mp_obj, Evas_Object_Line);
+   if (!o) return NULL;
+   EVAS_MEMPOOL_PREP(_mp_obj, o, Evas_Object_Line);
    o->magic = MAGIC_OBJ_LINE;
    o->cur.x1 = 0;
    o->cur.y1 = 0;
index 04099dc..fe26a76 100644 (file)
@@ -1,11 +1,13 @@
 #include "evas_common.h"
 #include "evas_private.h"
 
+EVAS_MEMPOOL(_mp_obj);
+EVAS_MEMPOOL(_mp_sh);
+
 static Eina_Inlist *
 get_layer_objects(Evas_Layer *l)
 {
-   if( !l || !l->objects ) return NULL;
-
+   if ((!l) || (!l->objects)) return NULL;
    return (EINA_INLIST_GET(l->objects));
 }
 
@@ -15,9 +17,11 @@ evas_object_new(Evas *e __UNUSED__)
 {
    Evas_Object *obj;
 
-   obj = calloc(1, sizeof(Evas_Object));
+   EVAS_MEMPOOL_INIT(_mp_obj, "evas_object", Evas_Object, 512, NULL);
+   obj = EVAS_MEMPOOL_ALLOC(_mp_obj, Evas_Object);
    if (!obj) return NULL;
-
+   EVAS_MEMPOOL_PREP(_mp_obj, obj, Evas_Object);
+  
    obj->magic = MAGIC_OBJ;
    obj->cur.scale = 1.0;
    obj->prev.scale = 1.0;
@@ -51,8 +55,11 @@ evas_object_free(Evas_Object *obj, int clean_layer)
        free(node);
      }
    obj->magic = 0;
-   if (obj->size_hints) free(obj->size_hints);
-   free(obj);
+   if (obj->size_hints)
+     {
+       EVAS_MEMPOOL_FREE(_mp_sh, obj->size_hints);
+     }
+   EVAS_MEMPOOL_FREE(_mp_obj, obj);
 }
 
 void
@@ -587,7 +594,10 @@ _evas_object_size_hint_alloc(Evas_Object *obj)
 {
    if (obj->size_hints) return;
 
-   obj->size_hints = calloc(1, sizeof(Evas_Size_Hints));
+   EVAS_MEMPOOL_INIT(_mp_sh, "evas_size_hints", Evas_Size_Hints, 512, );
+   obj->size_hints = EVAS_MEMPOOL_ALLOC(_mp_sh, Evas_Size_Hints);
+   if (!obj->size_hints) return;
+   EVAS_MEMPOOL_PREP(_mp_sh, obj->size_hints, Evas_Size_Hints);
    obj->size_hints->max.w = -1;
    obj->size_hints->max.h = -1;
    obj->size_hints->align.x = 0.5;
index 120b3d0..bf738a9 100644 (file)
@@ -80,6 +80,8 @@ static const Evas_Object_Func object_func =
  * @{
  */
 
+EVAS_MEMPOOL(_mp_obj);
+
 /**
  * Adds a new evas polygon object to the given evas.
  * @param   e The given evas.
@@ -281,7 +283,10 @@ evas_object_polygon_new(void)
    Evas_Object_Polygon *o;
 
    /* alloc obj private data */
-   o = calloc(1, sizeof(Evas_Object_Polygon));
+   EVAS_MEMPOOL_INIT(_mp_obj, "evas_object_polygon", Evas_Object_Polygon, 32, NULL);
+   o = EVAS_MEMPOOL_ALLOC(_mp_obj, Evas_Object_Polygon);
+   if (!o) return NULL;
+   EVAS_MEMPOOL_PREP(_mp_obj, o, Evas_Object_Polygon);
    o->magic = MAGIC_OBJ_POLYGON;
    return o;
 }
@@ -306,7 +311,7 @@ evas_object_polygon_free(Evas_Object *obj)
                                                                        obj->layer->evas->engine.data.context,
                                                                        o->engine_data);
    o->magic = 0;
-   free(o);
+   EVAS_MEMPOOL_FREE(_mp_obj, o);
 }
 
 static void
index e89143f..74ecac8 100644 (file)
@@ -72,6 +72,8 @@ static const Evas_Object_Func object_func =
  * @{
  */
 
+EVAS_MEMPOOL(_mp_obj);
+
 /**
  * Adds a rectangle to the given evas.
  * @param   e The given evas.
@@ -125,7 +127,10 @@ evas_object_rectangle_new(void)
    Evas_Object_Rectangle *o;
 
    /* alloc obj private data */
-   o = calloc(1, sizeof(Evas_Object_Rectangle));
+   EVAS_MEMPOOL_INIT(_mp_obj, "evas_object_rectangle", Evas_Object_Rectangle, 256, NULL);
+   o = EVAS_MEMPOOL_ALLOC(_mp_obj, Evas_Object_Rectangle);
+   if (!o) return NULL;
+   EVAS_MEMPOOL_PREP(_mp_obj, o, Evas_Object_Rectangle);
    o->magic = MAGIC_OBJ_RECTANGLE;
    return o;
 }
@@ -142,7 +147,7 @@ evas_object_rectangle_free(Evas_Object *obj)
    MAGIC_CHECK_END();
    /* free obj */
    o->magic = 0;
-   free(o);
+   EVAS_MEMPOOL_FREE(_mp_obj, o);
 }
 
 static void
index ac0ff0f..c3cde73 100644 (file)
@@ -64,6 +64,9 @@ static const Evas_Object_Func object_func =
      NULL
 };
 
+EVAS_MEMPOOL(_mp_obj);
+EVAS_MEMPOOL(_mp_cb);
+
 /* public funcs */
 /**
  * Store a pointer to user data for a smart object.
@@ -428,7 +431,10 @@ evas_object_smart_callback_add(Evas_Object *obj, const char *event, void (*func)
    MAGIC_CHECK_END();
    if (!event) return;
    if (!func) return;
-   cb = calloc(1, sizeof(Evas_Smart_Callback));
+   EVAS_MEMPOOL_INIT(_mp_cb, "evas_smart_callback", Evas_Smart_Callback, 512, );
+   cb = EVAS_MEMPOOL_ALLOC(_mp_cb, Evas_Smart_Callback);
+   if (!cb) return;
+   EVAS_MEMPOOL_PREP(_mp_cb, cb, Evas_Smart_Callback);
    cb->event = eina_stringshare_add(event);
    cb->func = func;
    cb->func_data = (void *)data;
@@ -887,7 +893,7 @@ evas_object_smart_callbacks_clear(Evas_Object *obj)
          {
             o->callbacks = eina_list_remove(o->callbacks, cb);
             if (cb->event) eina_stringshare_del(cb->event);
-            free(cb);
+             EVAS_MEMPOOL_FREE(_mp_cb, cb);
          }
      }
 }
@@ -925,7 +931,7 @@ evas_object_smart_cleanup(Evas_Object *obj)
             cb = o->callbacks->data;
             o->callbacks = eina_list_remove(o->callbacks, cb);
             if (cb->event) eina_stringshare_del(cb->event);
-            free(cb);
+             EVAS_MEMPOOL_FREE(_mp_cb, cb);
          }
 
        evas_smart_cb_descriptions_resize(&o->callbacks_descriptions, 0);
@@ -1022,7 +1028,10 @@ evas_object_smart_new(void)
    Evas_Object_Smart *o;
 
    /* alloc obj private data */
-   o = calloc(1, sizeof(Evas_Object_Smart));
+   EVAS_MEMPOOL_INIT(_mp_obj, "evas_object_smart", Evas_Object_Smart, 256, NULL);
+   o = EVAS_MEMPOOL_ALLOC(_mp_obj, Evas_Object_Smart);
+   if (!o) return NULL;
+   EVAS_MEMPOOL_PREP(_mp_obj, o, Evas_Object_Smart);
    o->magic = MAGIC_OBJ_SMART;
    return o;
 }
@@ -1039,7 +1048,7 @@ evas_object_smart_free(Evas_Object *obj)
    MAGIC_CHECK_END();
    /* free obj */
    o->magic = 0;
-   free(o);
+   EVAS_MEMPOOL_FREE(_mp_obj, o);
 }
 
 static void
index 5b5d578..3357cb4 100644 (file)
@@ -67,7 +67,7 @@ evas_object_smart_clipped_smart_add(Evas_Object *obj)
 
    cso = evas_object_smart_data_get(obj);
    if (!cso)
-     cso = malloc(sizeof(*cso)); /* users can provide it or realloc() later */
+     cso = calloc(1, sizeof(*cso)); /* users can provide it or realloc() later */
 
    cso->evas = evas_object_evas_get(obj);
    clipper = evas_object_rectangle_add(cso->evas);
index 1f9b491..8605cfe 100644 (file)
@@ -88,6 +88,8 @@ static const Evas_Object_Func object_func =
  * @{
  */
 
+EVAS_MEMPOOL(_mp_obj);
+
 /**
  * Creates a new text @c Evas_Object on the provided @c Evas canvas.
  *
@@ -1510,7 +1512,10 @@ evas_object_text_new(void)
    Evas_Object_Text *o;
 
    /* alloc obj private data */
-   o = calloc(1, sizeof(Evas_Object_Text));
+   EVAS_MEMPOOL_INIT(_mp_obj, "evas_object_text", Evas_Object_Text, 128, NULL);
+   o = EVAS_MEMPOOL_ALLOC(_mp_obj, Evas_Object_Text);
+   if (!o) return NULL;
+   EVAS_MEMPOOL_PREP(_mp_obj, o, Evas_Object_Text);
    o->magic = MAGIC_OBJ_TEXT;
    o->prev = o->cur;
 #ifdef BIDI_SUPPORT
@@ -1539,7 +1544,7 @@ evas_object_text_free(Evas_Object *obj)
    evas_bidi_props_clean(&o->cur.intl_props);
 #endif
    o->magic = 0;
-   free(o);
+   EVAS_MEMPOOL_FREE(_mp_obj, o);
 }
 
 static void
index b56f727..384a668 100644 (file)
@@ -784,6 +784,7 @@ static const char escape_strings[] =
 "&bull;\0"     "\xe2\x80\xa2\0"
 ;
 
+EVAS_MEMPOOL(_mp_obj);
 
 /**
  * @internal
@@ -7170,7 +7171,10 @@ evas_object_textblock_new(void)
    Evas_Object_Textblock *o;
 
    /* alloc obj private data */
-   o = calloc(1, sizeof(Evas_Object_Textblock));
+   EVAS_MEMPOOL_INIT(_mp_obj, "evas_object_textblock", Evas_Object_Textblock, 64, NULL);
+   o = EVAS_MEMPOOL_ALLOC(_mp_obj, Evas_Object_Textblock);
+   if (!o) return NULL;
+   EVAS_MEMPOOL_PREP(_mp_obj, o, Evas_Object_Textblock);
    o->magic = MAGIC_OBJ_TEXTBLOCK;
    o->cursor = calloc(1, sizeof(Evas_Textblock_Cursor));
    _format_command_init();
@@ -7196,8 +7200,8 @@ evas_object_textblock_free(Evas_Object *obj)
      }
    if (o->repch) eina_stringshare_del(o->repch);
    o->magic = 0;
-   free(o);
-   _format_command_shutdown();
+   EVAS_MEMPOOL_FREE(_mp_obj, o);
+  _format_command_shutdown();
 }
 
 
index 96707fa..737ab72 100644 (file)
@@ -821,7 +821,64 @@ void evas_render_object_recalc(Evas_Object *obj);
 Eina_Bool evas_map_inside_get(const Evas_Map *m, Evas_Coord x, Evas_Coord y);
 Eina_Bool evas_map_coords_get(const Evas_Map *m, Evas_Coord x, Evas_Coord y, Evas_Coord *mx, Evas_Coord *my, int grab);
 
-         
+/****************************************************************************/
+/*****************************************/
+/********************/
+//#define MPOOL 1
+
+#ifdef MPOOL 
+typedef struct _Evas_Mempool Evas_Mempool;
+  
+struct _Evas_Mempool
+{
+  int           count;
+  int           num_allocs;
+  int           num_frees;
+  Eina_Mempool *mp;
+};
+# define EVAS_MEMPOOL(x) \
+   static Evas_Mempool x = {0, 0, 0, NULL}
+# define EVAS_MEMPOOL_INIT(x, nam, siz, cnt, ret) \
+   do { \
+     if (!x.mp) { \
+       x.mp = eina_mempool_add("chained_mempool", nam, NULL, sizeof(siz), cnt); \
+       if (!x.mp) { \
+         return ret; \
+       } \
+     } \
+   } while (0)
+# define EVAS_MEMPOOL_ALLOC(x, siz) \
+   eina_mempool_malloc(x.mp, sizeof(siz))
+# define EVAS_MEMPOOL_PREP(x, p, siz) \
+   do { \
+     x.count++; \
+     x.num_allocs++; \
+     memset(p, 0, sizeof(siz)); \
+   } while (0)
+# define EVAS_MEMPOOL_FREE(x, p) \
+   do { \
+     eina_mempool_free(x.mp, p); \
+     x.count--; \
+     x.num_frees++; \
+     if (x.count <= 0) { \
+       eina_mempool_del(x.mp); \
+       x.mp = NULL; \
+       x.count = 0; \
+     } \
+   } while (0)
+#else
+# define EVAS_MEMPOOL(x)
+# define EVAS_MEMPOOL_INIT(x, nam, siz, cnt, ret)
+# define EVAS_MEMPOOL_PREP(x, p, siz)
+# define EVAS_MEMPOOL_ALLOC(x, siz) \
+   calloc(1, sizeof(siz))
+# define EVAS_MEMPOOL_FREE(x, p) \
+   free(p)
+#endif  
+/********************/
+/*****************************************/
+/****************************************************************************/
+  
 #define EVAS_API_OVERRIDE(func, api, prefix) \
      (api)->func = prefix##func