summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeeyong Um <conr2d@gmail.com>2017-03-23 21:27:28 +0900
committerJeeyong Um <conr2d@gmail.com>2017-03-23 21:27:28 +0900
commit4c419498f22498ad3458c681d2969289c1348484 (patch)
treed11a853c03a49a00b7331fe7567fcfe0e8037b1e
parent8fd02a97cc4118513128a29be87f0cf0b8f8db90 (diff)
Efl.Observable: Extract method deleting observer
-rw-r--r--src/lib/efl/interfaces/efl_observer.c43
1 files changed, 19 insertions, 24 deletions
diff --git a/src/lib/efl/interfaces/efl_observer.c b/src/lib/efl/interfaces/efl_observer.c
index 2cf8e34df7..9316529ba3 100644
--- a/src/lib/efl/interfaces/efl_observer.c
+++ b/src/lib/efl/interfaces/efl_observer.c
@@ -49,6 +49,23 @@ _free_cb(void *data)
49 free(observers); 49 free(observers);
50} 50}
51 51
52static void
53_observer_del(Eo *obj EINA_UNUSED, Efl_Observable_Data *pd, Efl_Observer_List *observers, Eina_List *target)
54{
55 if (!target) return;
56
57 Efl_Observer_Refcount *or;
58
59 or = eina_list_data_get(target);
60 EINA_REFCOUNT_UNREF(or)
61 {
62 observers->list = eina_list_remove_list(observers->list, target);
63
64 if (!observers->list)
65 eina_hash_del(pd->observers, observers->key, observers);
66 }
67}
68
52EOLIAN static void 69EOLIAN static void
53_efl_observable_efl_object_destructor(Eo *obj, Efl_Observable_Data *pd) 70_efl_observable_efl_object_destructor(Eo *obj, Efl_Observable_Data *pd)
54{ 71{
@@ -97,25 +114,13 @@ EOLIAN static void
97_efl_observable_observer_del(Eo *obj EINA_UNUSED, Efl_Observable_Data *pd, const char *key, Efl_Observer *obs) 114_efl_observable_observer_del(Eo *obj EINA_UNUSED, Efl_Observable_Data *pd, const char *key, Efl_Observer *obs)
98{ 115{
99 Efl_Observer_List *observers; 116 Efl_Observer_List *observers;
100 Efl_Observer_Refcount *or;
101 Eina_List *list;
102 117
103 if (!key || !pd->observers) return; 118 if (!key || !pd->observers) return;
104 119
105 observers = eina_hash_find(pd->observers, key); 120 observers = eina_hash_find(pd->observers, key);
106 if (!observers) return; 121 if (!observers) return;
107 122
108 list = eina_list_search_sorted_list(observers->list, _search_cb, obs); 123 _observer_del(obj, pd, observers, eina_list_search_sorted_list(observers->list, _search_cb, obs));
109 if (!list) return;
110
111 or = eina_list_data_get(list);
112 EINA_REFCOUNT_UNREF(or)
113 {
114 observers->list = eina_list_remove_list(observers->list, list);
115
116 if (observers->list == NULL)
117 eina_hash_del(pd->observers, key, observers);
118 }
119} 124}
120 125
121EOLIAN static void 126EOLIAN static void
@@ -129,17 +134,7 @@ _efl_observable_observer_clean(Eo *obj EINA_UNUSED, Efl_Observable_Data *pd, Efl
129 it = eina_hash_iterator_data_new(pd->observers); 134 it = eina_hash_iterator_data_new(pd->observers);
130 EINA_ITERATOR_FOREACH(it, observers) 135 EINA_ITERATOR_FOREACH(it, observers)
131 { 136 {
132 Efl_Observer_Refcount *or; 137 _observer_del(obj, pd, observers, eina_list_search_sorted_list(observers->list, _search_cb, obs));
133 Eina_List *list;
134
135 list = eina_list_search_sorted_list(observers->list, _search_cb, obs);
136 if (!list) continue;
137
138 or = eina_list_data_get(list);
139 EINA_REFCOUNT_UNREF(or)
140 {
141 observers->list = eina_list_remove_list(observers->list, list);
142 }
143 } 138 }
144 eina_iterator_free(it); 139 eina_iterator_free(it);
145} 140}