summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeeyong Um <conr2d@gmail.com>2017-03-23 02:48:20 +0900
committerJeeyong Um <conr2d@gmail.com>2017-03-23 02:48:20 +0900
commit782d625ac5a337b3de241c295721443d82723586 (patch)
treee0cceedd9d0367f19d1bee8e7d4cba68589ff2fa
parent2787f0fe5dfe1e880a07bf957aa2a111866f25dc (diff)
Efl.Observable: Delay creation of observers hash
-rw-r--r--src/lib/efl/interfaces/efl_observable.eo1
-rw-r--r--src/lib/efl/interfaces/efl_observer.c33
2 files changed, 18 insertions, 16 deletions
diff --git a/src/lib/efl/interfaces/efl_observable.eo b/src/lib/efl/interfaces/efl_observable.eo
index 683c64f5b4..d5a4bb9c0d 100644
--- a/src/lib/efl/interfaces/efl_observable.eo
+++ b/src/lib/efl/interfaces/efl_observable.eo
@@ -58,7 +58,6 @@ class Efl.Observable (Efl.Object) {
58 } 58 }
59 } 59 }
60 implements { 60 implements {
61 Efl.Object.constructor;
62 Efl.Object.destructor; 61 Efl.Object.destructor;
63 } 62 }
64} 63}
diff --git a/src/lib/efl/interfaces/efl_observer.c b/src/lib/efl/interfaces/efl_observer.c
index 2d4a20bbc6..6e3c2e77b0 100644
--- a/src/lib/efl/interfaces/efl_observer.c
+++ b/src/lib/efl/interfaces/efl_observer.c
@@ -13,20 +13,11 @@ typedef struct
13 Efl_Observer *o; 13 Efl_Observer *o;
14} Efl_Observer_Refcount; 14} Efl_Observer_Refcount;
15 15
16EOLIAN static Eo *
17_efl_observable_efl_object_constructor(Efl_Object *obj, Efl_Observable_Data *pd)
18{
19 pd->observers = eina_hash_string_superfast_new((Eina_Free_Cb)eina_hash_free);
20
21 obj = efl_constructor(efl_super(obj, EFL_OBSERVABLE_CLASS));
22
23 return obj;
24}
25
26EOLIAN static void 16EOLIAN static void
27_efl_observable_efl_object_destructor(Eo *obj, Efl_Observable_Data *pd) 17_efl_observable_efl_object_destructor(Eo *obj, Efl_Observable_Data *pd)
28{ 18{
29 eina_hash_free(pd->observers); 19 if (pd->observers)
20 eina_hash_free(pd->observers);
30 21
31 efl_destructor(efl_super(obj, EFL_OBSERVABLE_CLASS)); 22 efl_destructor(efl_super(obj, EFL_OBSERVABLE_CLASS));
32} 23}
@@ -34,12 +25,16 @@ _efl_observable_efl_object_destructor(Eo *obj, Efl_Observable_Data *pd)
34EOLIAN static void 25EOLIAN static void
35_efl_observable_observer_add(Eo *obj EINA_UNUSED, Efl_Observable_Data *pd, const char *key, Efl_Observer *obs) 26_efl_observable_observer_add(Eo *obj EINA_UNUSED, Efl_Observable_Data *pd, const char *key, Efl_Observer *obs)
36{ 27{
37 Eina_Hash *observers; 28 Eina_Hash *observers = NULL;
38 Efl_Observer_Refcount *or; 29 Efl_Observer_Refcount *or;
39 30
40 if (!key) return; 31 if (!key) return;
41 32
42 observers = eina_hash_find(pd->observers, key); 33 if (pd->observers)
34 observers = eina_hash_find(pd->observers, key);
35 else
36 pd->observers = eina_hash_string_superfast_new(NULL);
37
43 if (!observers) 38 if (!observers)
44 { 39 {
45 observers = eina_hash_pointer_new(free); 40 observers = eina_hash_pointer_new(free);
@@ -67,7 +62,7 @@ _efl_observable_observer_del(Eo *obj EINA_UNUSED, Efl_Observable_Data *pd, const
67 Eina_Hash *observers; 62 Eina_Hash *observers;
68 Efl_Observer_Refcount *or; 63 Efl_Observer_Refcount *or;
69 64
70 if (!key) return; 65 if (!key || !pd->observers) return;
71 66
72 observers = eina_hash_find(pd->observers, key); 67 observers = eina_hash_find(pd->observers, key);
73 if (!observers) return; 68 if (!observers) return;
@@ -92,6 +87,8 @@ _efl_observable_observer_clean(Eo *obj EINA_UNUSED, Efl_Observable_Data *pd, Efl
92 Eina_Iterator *it; 87 Eina_Iterator *it;
93 Eina_Hash *observers; 88 Eina_Hash *observers;
94 89
90 if (!pd->observers) return;
91
95 it = eina_hash_iterator_data_new(pd->observers); 92 it = eina_hash_iterator_data_new(pd->observers);
96 EINA_ITERATOR_FOREACH(it, observers) 93 EINA_ITERATOR_FOREACH(it, observers)
97 { 94 {
@@ -150,6 +147,8 @@ _efl_observable_observers_iterator_new(Eo *obj EINA_UNUSED, Efl_Observable_Data
150 Eina_Hash *observers; 147 Eina_Hash *observers;
151 Efl_Observer_Iterator *it; 148 Efl_Observer_Iterator *it;
152 149
150 if (!pd->observers) return NULL;
151
153 observers = eina_hash_find(pd->observers, key); 152 observers = eina_hash_find(pd->observers, key);
154 if (!observers) return NULL; 153 if (!observers) return NULL;
155 154
@@ -168,11 +167,13 @@ _efl_observable_observers_iterator_new(Eo *obj EINA_UNUSED, Efl_Observable_Data
168} 167}
169 168
170EOLIAN static void 169EOLIAN static void
171_efl_observable_observers_update(Eo *obj, Efl_Observable_Data *pd EINA_UNUSED, const char *key, void *data) 170_efl_observable_observers_update(Eo *obj, Efl_Observable_Data *pd, const char *key, void *data)
172{ 171{
173 Eina_Iterator *it; 172 Eina_Iterator *it;
174 Efl_Observer *o; 173 Efl_Observer *o;
175 174
175 if (!pd->observers) return;
176
176 it = efl_observable_observers_iterator_new(obj, key); 177 it = efl_observable_observers_iterator_new(obj, key);
177 if (!it) return; 178 if (!it) return;
178 179
@@ -240,6 +241,8 @@ _efl_observable_iterator_tuple_new(Eo *obj, Efl_Observable_Data *pd)
240{ 241{
241 Efl_Observable_Iterator *it; 242 Efl_Observable_Iterator *it;
242 243
244 if (!pd->observers) return NULL;
245
243 it = calloc(1, sizeof(Efl_Observable_Iterator)); 246 it = calloc(1, sizeof(Efl_Observable_Iterator));
244 if (!it) return NULL; 247 if (!it) return NULL;
245 248