hermet pushed a commit to branch master.

http://git.enlightenment.org/tools/enventor.git/commit/?id=6f9d51e28b7017579e42e682cbe81288c96e6ea9

commit 6f9d51e28b7017579e42e682cbe81288c96e6ea9
Author: Hermet Park <her...@hermet.pe.kr>
Date:   Sat Apr 23 13:27:58 2016 +0900

    edc_navigator: optimize state update logic.
    
    don't need to flush every updation time.
    we only update changed states.
---
 src/bin/edc_navigator.c | 53 +++++++++++++++++++++++++++++++++++++++++++------
 1 file changed, 47 insertions(+), 6 deletions(-)

diff --git a/src/bin/edc_navigator.c b/src/bin/edc_navigator.c
index 8a4d758..44aeef4 100644
--- a/src/bin/edc_navigator.c
+++ b/src/bin/edc_navigator.c
@@ -85,6 +85,8 @@ struct state_it_s
    char *name;
    Elm_Object_Item *it;
    part_it *pit;
+
+   Eina_Bool discarded : 1;
 };
 
 struct program_it_s
@@ -653,23 +655,50 @@ gl_state_selected_cb(void *data, Evas_Object *obj 
EINA_UNUSED,
 static void
 states_update(navi_data *nd, part_it *pit)
 {
-   navigator_states_clear(pit);
-
    Evas_Object *enventor = base_enventor_get();
    Eina_List *state_list = enventor_object_part_states_list_get(enventor,
                                                                 pit->name);
-   if (!state_list) return;
-
-   //Append state list
    char *name;
-   Eina_List *l;
+   Eina_List *l, *ll;
    state_it *sit;
    int idx = 0;
 
+   if (!state_list)
+     {
+        navigator_states_clear(pit);
+        return;
+     }
+
+   //1. Prepare for validation.
+   EINA_LIST_FOREACH(pit->states, l, sit)
+     {
+        sit->discarded = EINA_TRUE;
+        sit->tag.idx = IDX_MAX;
+     }
+
+   //2. New States
    EINA_LIST_FOREACH(state_list, l, name)
      {
+        Eina_Bool new_state = EINA_TRUE;
         idx++;
 
+        //Check if it is existed?
+        EINA_LIST_FOREACH(pit->states, ll, sit)
+          {
+             if (!strcmp(name, sit->name) &&
+                 (strlen(name) == strlen(sit->name)))
+               {
+                  sit->discarded = EINA_FALSE;
+                  new_state = EINA_FALSE;
+                  //update index of the item
+                  sit->tag.idx = idx;
+                  break;
+               }
+
+          }
+        if (!new_state) continue;
+
+        //Ok, this state is newly added
         sit = calloc(1, sizeof(state_it));
         if (!sit)
           {
@@ -695,6 +724,18 @@ states_update(navi_data *nd, part_it *pit)
         pit->states = eina_list_append(pit->states, sit);
      }
 
+   //3. Update states
+   EINA_LIST_FOREACH_SAFE(pit->states, l, ll, sit)
+     {
+        //Remove them from the previous list.
+        if (sit->discarded)
+          {
+             pit->states = eina_list_remove_list(pit->states, l);
+             navigator_state_free(sit);
+             continue;
+          }
+     }
+
    edje_edit_string_list_free(state_list);
 }
 

-- 


Reply via email to