[Genlist] Optimization for genlist memory operation 14/218014/6
authorGodly Thekkethottiyil Alias <godly.talias@samsung.com>
Mon, 18 Nov 2019 15:18:47 +0000 (20:48 +0530)
committerSangHyeon Lee <sh10233.lee@samsung.com>
Thu, 12 Dec 2019 06:17:02 +0000 (06:17 +0000)
Replaced malloc operations with eina mempool for better performance

Change-Id: I073e2d69547b700235eb96859b8eea37a53f231d
Signed-off-by: Godly Thekkethottiyil Alias <godly.talias@samsung.com>
src/lib/elementary_tizen/elm_genlist.c
src/lib/elementary_tizen/elm_widget_genlist.h

index 7b581f3..33e181d 100644 (file)
@@ -1594,7 +1594,9 @@ _item_cache_free(Elm_Genlist_Data *sd, Item_Cache *ic)
    sd->item_cache = eina_inlist_remove(sd->item_cache, EINA_INLIST_GET(ic));
    sd->item_cache_count--;
    // Free should be performed after inlist is poped
-   free(ic);
+   //TIZEN_ONLY(20191211): Mempool for genlist
+   eina_mempool_free(sd->_genlist_itemcache_mp, ic);
+   //
 }
 
 static void
@@ -1635,7 +1637,7 @@ _item_cache_push(Elm_Gen_Item *it, Eina_List *contents)
         _item_cache_free(sd, ic);
      }
 
-   ic = ELM_NEW(Item_Cache);
+   ic = eina_mempool_calloc(sd->_genlist_itemcache_mp, sizeof(Item_Cache));
    if (!ic)
      {
         if (VIEW(it)) evas_object_del(VIEW(it));
@@ -1691,7 +1693,9 @@ _item_cache_pop(Elm_Gen_Item *it)
 
              eina_list_free(ic->contents);
              ic->contents = NULL;
-             free(ic);
+             //TIZEN_ONLY(20191211): Mempool for genlist
+             eina_mempool_free(sd->_genlist_itemcache_mp, ic);
+             //
              return EINA_TRUE;
           }
      }
@@ -4936,7 +4940,9 @@ _item_block_del(Elm_Gen_Item *it)
           eina_inlist_remove(GL_IT(it)->wsd->blocks, il);
         GL_IT(it)->wsd->blocks_realized = eina_list_remove
            (GL_IT(it)->wsd->blocks_realized, itb);
-        free(itb);
+        //TIZEN_ONLY(20191211): Mempool for genlist
+        eina_mempool_free(sd->_genlist_itemblock_mp, itb);
+        //
         itb = NULL;
         if (itbn) itbn->calc_done = EINA_FALSE;
      }
@@ -4964,7 +4970,9 @@ _item_block_del(Elm_Gen_Item *it)
                       (GL_IT(it)->wsd->blocks, EINA_INLIST_GET(itb));
                   GL_IT(it)->wsd->blocks_realized = eina_list_remove
                      (GL_IT(it)->wsd->blocks_realized, itb);
-                  free(itb);
+                  //TIZEN_ONLY(20191211): Mempool for genlist
+                  eina_mempool_free(sd->_genlist_itemblock_mp, itb);
+                  //
                   block_changed = EINA_TRUE;
                }
              /* merge block with next */
@@ -4981,7 +4989,9 @@ _item_block_del(Elm_Gen_Item *it)
                                        EINA_INLIST_GET(itbn));
                   GL_IT(it)->wsd->blocks_realized = eina_list_remove
                      (GL_IT(it)->wsd->blocks_realized, itbn);
-                  free(itbn);
+                  //TIZEN_ONLY(20191211): Mempool for genlist
+                  eina_mempool_free(sd->_genlist_itemblock_mp, itbn);
+                  //
                   block_changed = EINA_TRUE;
                }
           }
@@ -5290,7 +5300,9 @@ _item_block_new(Elm_Genlist_Data *sd,
 {
    Item_Block *itb;
 
-   itb = calloc(1, sizeof(Item_Block));
+   //TIZEN_ONLY(20191211): Mempool for genlist
+   itb = eina_mempool_calloc(sd->_genlist_itemblock_mp, sizeof(Item_Block));
+   //
    if (!itb) return NULL;
    itb->sd = sd;
    if (prepend)
@@ -5328,7 +5340,9 @@ _item_block_add(Elm_Genlist_Data *sd,
 newblock:
         if (GL_IT(it)->rel)
           {
-             itb = calloc(1, sizeof(Item_Block));
+             //TIZEN_ONLY(20191211): Mempool for genlist
+             itb = eina_mempool_calloc(sd->_genlist_itemblock_mp, sizeof(Item_Block));
+             //
              if (!itb) return EINA_FALSE;
              itb->sd = sd;
              if (!GL_IT(it)->rel->item->block)
@@ -5535,7 +5549,9 @@ newblock:
         if (!done)
           {
              /* moving items to new block */
-             itb2 = calloc(1, sizeof(Item_Block));
+             //TIZEN_ONLY(20191211): Mempool for genlist
+             itb2 = eina_mempool_calloc(sd->_genlist_itemblock_mp, sizeof(Item_Block));
+             //
              if (!itb2) return EINA_FALSE;
              itb2->sd = sd;
              sd->blocks =
@@ -6638,6 +6654,7 @@ _elm_genlist_efl_canvas_group_group_add(Eo *obj, Elm_Genlist_Data *priv)
 {
    ELM_WIDGET_DATA_GET_OR_RETURN(obj, wd);
    Evas_Coord minw, minh;
+   const char *choice, *tmp;
    Elm_Genlist_Pan_Data *pan_data;
 
    efl_canvas_group_add(efl_super(obj, MY_CLASS));
@@ -6652,6 +6669,42 @@ _elm_genlist_efl_canvas_group_group_add(Eo *obj, Elm_Genlist_Data *priv)
    evas_object_smart_member_add(priv->hit_rect, obj);
    elm_widget_sub_object_add(obj, priv->hit_rect);
 
+//TIZEN_ONLY(20191211): Mempool for genlist
+#ifdef EINA_DEFAULT_MEMPOOL
+   choice = "pass_through";
+#else
+   choice = "chained_mempool";
+#endif
+   tmp = getenv("EINA_MEMPOOL");
+   if (tmp && tmp[0])
+     choice = tmp;
+
+   priv->_genlist_itemdata_mp = eina_mempool_add
+                   (choice, "genlist_item_data", NULL, sizeof(Elm_Gen_Item_Type), 128);
+   if (!priv->_genlist_itemdata_mp)
+     CRI("ERROR: Memory not enough for creating mempool for genlist items");
+
+   priv->_genlist_itemblock_mp = eina_mempool_add
+                    (choice, "genlist_item_block", NULL, sizeof(Item_Block), 16);
+   if (!priv->_genlist_itemblock_mp)
+     {
+        eina_mempool_del(priv->_genlist_itemdata_mp);
+        priv->_genlist_itemdata_mp = NULL;
+        CRI("ERROR: Memory not enough for creating mempool for genlist item blocks");
+     }
+
+   priv->_genlist_itemcache_mp = eina_mempool_add
+                    (choice, "genlist_item_cache", NULL, sizeof(Item_Cache), 16);
+   if (!priv->_genlist_itemcache_mp)
+     {
+        eina_mempool_del(priv->_genlist_itemdata_mp);
+        eina_mempool_del(priv->_genlist_itemblock_mp);
+        priv->_genlist_itemdata_mp = NULL;
+        priv->_genlist_itemblock_mp = NULL;
+        CRI("ERROR: Memory not enough for creating mempool for genlist item cache");
+     }
+//
+
    /* common scroller hit rectangle setup */
    evas_object_color_set(priv->hit_rect, 0, 0, 0, 0);
    evas_object_show(priv->hit_rect);
@@ -6774,6 +6827,11 @@ _elm_genlist_efl_canvas_group_group_del(Eo *obj, Elm_Genlist_Data *sd)
    if (sd->size_caches) eina_hash_free(sd->size_caches);
    if (sd->decorate_it_type) eina_stringshare_del(sd->decorate_it_type);
    if (sd->clipee) evas_object_del(sd->clipee);
+   //TIZEN_ONLY(20191211): Mempool for genlist
+   if (sd->_genlist_itemdata_mp) eina_mempool_del(sd->_genlist_itemdata_mp);
+   if (sd->_genlist_itemblock_mp) eina_mempool_del(sd->_genlist_itemblock_mp);
+   if (sd->_genlist_itemcache_mp) eina_mempool_del(sd->_genlist_itemcache_mp);
+   //
 
    evas_object_del(sd->pan_obj);
    efl_canvas_group_del(efl_super(obj, MY_CLASS));
@@ -7253,7 +7311,9 @@ end:
      }
 
    elm_genlist_item_class_unref((Elm_Genlist_Item_Class *)it->itc);
-   free(GL_IT(it));
+   //TIZEN_ONLY(20191211): Mempool for genlist
+   eina_mempool_free(sd->_genlist_itemdata_mp, GL_IT(it));
+   //
    GL_IT(it) = NULL;
 
 // TIZEN_ONLY(20150703) : banded color background feature. enabled only un-scrollable
@@ -7387,7 +7447,9 @@ _elm_genlist_item_new(Elm_Genlist_Data *sd,
    it->func.func = func;
    it->func.data = func_data;
 
-   GL_IT(it) = ELM_NEW(Elm_Gen_Item_Type);
+   //TIZEN_ONLY(20191211): Mempool for genlist
+   GL_IT(it) = eina_mempool_calloc(sd->_genlist_itemdata_mp, sizeof(Elm_Gen_Item_Type));
+   //
    GL_IT(it)->wsd = sd;
    GL_IT(it)->type = type;
 
index bfc48b7..8d012c5 100644 (file)
@@ -306,6 +306,12 @@ struct _Elm_Genlist_Data
    Eina_Bool                             bottom_margin_enabled : 1;
    Eina_Bool                             unhighlighted : 1;
    Eina_Bool                             on_clear : 1;
+
+//TIZEN_ONLY(20191211): Mempool for genlist
+   Eina_Mempool                          *_genlist_itemdata_mp;
+   Eina_Mempool                          *_genlist_itemblock_mp;
+   Eina_Mempool                          *_genlist_itemcache_mp;
+//
 };
 
 typedef struct _Item_Block Item_Block;