evas common: remove lru optimization. 18/267518/2
authorHermet Park <chuneon.park@samsung.com>
Mon, 6 Dec 2021 12:01:53 +0000 (21:01 +0900)
committerHermet Park <chuneon.park@samsung.com>
Mon, 6 Dec 2021 12:06:23 +0000 (21:06 +0900)
This lru optimization is useless because we have already reference count,
Actually, we can't remove the data even though the cache capacity is full
because those are completed referenced.

This mis-implementation occurs the memory leak.

Change-Id: If25e843bcbb6759df81e87c076a002bf771ea1b1

src/lib/evas/common/evas_common_generic_cache.c

index c1367b8..c040e00 100644 (file)
@@ -1,7 +1,5 @@
 #include "evas_common_private.h"
 
-#define LRU_CACHE_LIMIT 25
-
 EAPI Generic_Cache*
 generic_cache_new(void *user_data, Generic_Cache_Free func)
 {
@@ -55,19 +53,7 @@ generic_cache_data_set(Generic_Cache *cache, void *key, void *surface)
    entry->data = surface;
    entry->ref = 1;
    eina_hash_add(cache->hash, &key, entry);
-   cache->lru_list = eina_list_prepend(cache->lru_list, entry);
-   count = eina_list_count(cache->lru_list);
-
-   if (count > LRU_CACHE_LIMIT)
-   {
-      entry = eina_list_data_get(eina_list_last(cache->lru_list));
-      // if its still being ref.
-      if (entry->ref > 1) return;
-      eina_hash_del(cache->hash, &entry->key, entry);
-      cache->lru_list = eina_list_remove_list(cache->lru_list, eina_list_last(cache->lru_list));
-      cache->free_func(cache->user_data, entry->data);
-      free(entry);
-   }
+   cache->lru_list = eina_list_append(cache->lru_list, entry);
 }
 
 EAPI void *
@@ -80,16 +66,6 @@ generic_cache_data_get(Generic_Cache *cache, void *key)
    if (entry)
      {
         ++entry->ref;
-
-        //promote in lru
-        EINA_LIST_FOREACH(cache->lru_list, l, lru_data)
-          {
-            if (lru_data == entry)
-              {
-                 cache->lru_list = eina_list_promote_list(cache->lru_list, l);
-                 break;
-              }
-          }
         return entry->data;
      }
    return NULL;
@@ -100,7 +76,7 @@ generic_cache_data_drop(Generic_Cache *cache, void *key)
 {
    Generic_Cache_Entry *entry = NULL;
 
-   entry =  eina_hash_find(cache->hash, &key);
+   entry = eina_hash_find(cache->hash, &key);
    if (entry)
      {
         if (--entry->ref > 0) return;