summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeeyong Um <conr2d@gmail.com>2017-03-23 14:12:06 +0900
committerJeeyong Um <conr2d@gmail.com>2017-03-23 14:12:06 +0900
commita198859b8738bd2ae99689cc8d1767a49d3a3c07 (patch)
tree988a9a9ad928db151f166146abb33edfc5ef5943
parent782d625ac5a337b3de241c295721443d82723586 (diff)
Efl.Observable: Replace inner hash with list
-rw-r--r--src/lib/efl/interfaces/efl_observer.c76
1 files changed, 56 insertions, 20 deletions
diff --git a/src/lib/efl/interfaces/efl_observer.c b/src/lib/efl/interfaces/efl_observer.c
index 6e3c2e77b0..eb57fc45f4 100644
--- a/src/lib/efl/interfaces/efl_observer.c
+++ b/src/lib/efl/interfaces/efl_observer.c
@@ -9,10 +9,44 @@ typedef struct
9typedef struct 9typedef struct
10{ 10{
11 EINA_REFCOUNT; 11 EINA_REFCOUNT;
12
13 Efl_Observer *o; 12 Efl_Observer *o;
14} Efl_Observer_Refcount; 13} Efl_Observer_Refcount;
15 14
15typedef struct
16{
17 Eina_List *list;
18} Efl_Observer_List;
19
20static int
21_search_cb(const void *data1, const void *data2)
22{
23 const Efl_Observer_Refcount *or = data1;
24 const Efl_Observer *obs = data2;
25
26 if (or->o > obs) return 1;
27 else if (or->o < obs) return -1;
28 else return 0;
29}
30
31static int
32_insert_cb(const void *data1, const void *data2)
33{
34 const Efl_Observer_Refcount *or1 = data1;
35 const Efl_Observer_Refcount *or2 = data2;
36
37 if (or1->o > or2->o) return 1;
38 else if (or1->o < or2->o) return -1;
39 else return 0;
40}
41
42static void
43_free_cb(void *data)
44{
45 Efl_Observer_List *observers = data;
46 eina_list_free(observers->list);
47 free(observers);
48}
49
16EOLIAN static void 50EOLIAN static void
17_efl_observable_efl_object_destructor(Eo *obj, Efl_Observable_Data *pd) 51_efl_observable_efl_object_destructor(Eo *obj, Efl_Observable_Data *pd)
18{ 52{
@@ -25,7 +59,7 @@ _efl_observable_efl_object_destructor(Eo *obj, Efl_Observable_Data *pd)
25EOLIAN static void 59EOLIAN static void
26_efl_observable_observer_add(Eo *obj EINA_UNUSED, Efl_Observable_Data *pd, const char *key, Efl_Observer *obs) 60_efl_observable_observer_add(Eo *obj EINA_UNUSED, Efl_Observable_Data *pd, const char *key, Efl_Observer *obs)
27{ 61{
28 Eina_Hash *observers = NULL; 62 Efl_Observer_List *observers = NULL;
29 Efl_Observer_Refcount *or; 63 Efl_Observer_Refcount *or;
30 64
31 if (!key) return; 65 if (!key) return;
@@ -33,22 +67,22 @@ _efl_observable_observer_add(Eo *obj EINA_UNUSED, Efl_Observable_Data *pd, const
33 if (pd->observers) 67 if (pd->observers)
34 observers = eina_hash_find(pd->observers, key); 68 observers = eina_hash_find(pd->observers, key);
35 else 69 else
36 pd->observers = eina_hash_string_superfast_new(NULL); 70 pd->observers = eina_hash_string_superfast_new(_free_cb);
37 71
38 if (!observers) 72 if (!observers)
39 { 73 {
40 observers = eina_hash_pointer_new(free); 74 observers = calloc(1, sizeof(Efl_Observer_List));
41 eina_hash_add(pd->observers, key, observers); 75 eina_hash_add(pd->observers, key, observers);
42 } 76 }
43 77
44 or = eina_hash_find(observers, &obs); 78 or = eina_list_search_sorted(observers->list, _search_cb, obs);
45 if (!or) 79 if (!or)
46 { 80 {
47 or = calloc(1, sizeof(Efl_Observer_Refcount)); 81 or = calloc(1, sizeof(Efl_Observer_Refcount));
48 or->o = obs; 82 or->o = obs;
49 EINA_REFCOUNT_INIT(or); 83 EINA_REFCOUNT_INIT(or);
50 84
51 eina_hash_direct_add(observers, &or->o, or); 85 observers->list = eina_list_sorted_insert(observers->list, _insert_cb, or);
52 } 86 }
53 else 87 else
54 { 88 {
@@ -59,25 +93,25 @@ _efl_observable_observer_add(Eo *obj EINA_UNUSED, Efl_Observable_Data *pd, const
59EOLIAN static void 93EOLIAN static void
60_efl_observable_observer_del(Eo *obj EINA_UNUSED, Efl_Observable_Data *pd, const char *key, Efl_Observer *obs) 94_efl_observable_observer_del(Eo *obj EINA_UNUSED, Efl_Observable_Data *pd, const char *key, Efl_Observer *obs)
61{ 95{
62 Eina_Hash *observers; 96 Efl_Observer_List *observers;
63 Efl_Observer_Refcount *or; 97 Efl_Observer_Refcount *or;
98 Eina_List *list;
64 99
65 if (!key || !pd->observers) return; 100 if (!key || !pd->observers) return;
66 101
67 observers = eina_hash_find(pd->observers, key); 102 observers = eina_hash_find(pd->observers, key);
68 if (!observers) return; 103 if (!observers) return;
69 104
70 or = eina_hash_find(observers, &obs); 105 list = eina_list_search_sorted_list(observers->list, _search_cb, obs);
71 if (!or) return; 106 if (!list) return;
72 107
108 or = eina_list_data_get(list);
73 EINA_REFCOUNT_UNREF(or) 109 EINA_REFCOUNT_UNREF(or)
74 { 110 {
75 eina_hash_del(observers, &or->o, or); 111 observers->list = eina_list_remove_list(observers->list, list);
76 112
77 if (eina_hash_population(observers) == 0) 113 if (observers->list == NULL)
78 { 114 eina_hash_del(pd->observers, key, observers);
79 eina_hash_del(pd->observers, key, observers);
80 }
81 } 115 }
82} 116}
83 117
@@ -85,7 +119,7 @@ EOLIAN static void
85_efl_observable_observer_clean(Eo *obj EINA_UNUSED, Efl_Observable_Data *pd, Efl_Observer *obs) 119_efl_observable_observer_clean(Eo *obj EINA_UNUSED, Efl_Observable_Data *pd, Efl_Observer *obs)
86{ 120{
87 Eina_Iterator *it; 121 Eina_Iterator *it;
88 Eina_Hash *observers; 122 Efl_Observer_List *observers;
89 123
90 if (!pd->observers) return; 124 if (!pd->observers) return;
91 125
@@ -93,13 +127,15 @@ _efl_observable_observer_clean(Eo *obj EINA_UNUSED, Efl_Observable_Data *pd, Efl
93 EINA_ITERATOR_FOREACH(it, observers) 127 EINA_ITERATOR_FOREACH(it, observers)
94 { 128 {
95 Efl_Observer_Refcount *or; 129 Efl_Observer_Refcount *or;
130 Eina_List *list;
96 131
97 or = eina_hash_find(observers, &obs); 132 list = eina_list_search_sorted_list(observers->list, _search_cb, obs);
98 if (!or) continue; 133 if (!list) continue;
99 134
135 or = eina_list_data_get(list);
100 EINA_REFCOUNT_UNREF(or) 136 EINA_REFCOUNT_UNREF(or)
101 { 137 {
102 eina_hash_del(observers, &obs, or); 138 observers->list = eina_list_remove_list(observers->list, list);
103 } 139 }
104 } 140 }
105 eina_iterator_free(it); 141 eina_iterator_free(it);
@@ -144,7 +180,7 @@ _efl_observable_observers_iterator_free(Eina_Iterator *it)
144EOLIAN static Eina_Iterator * 180EOLIAN static Eina_Iterator *
145_efl_observable_observers_iterator_new(Eo *obj EINA_UNUSED, Efl_Observable_Data *pd, const char *key) 181_efl_observable_observers_iterator_new(Eo *obj EINA_UNUSED, Efl_Observable_Data *pd, const char *key)
146{ 182{
147 Eina_Hash *observers; 183 Efl_Observer_List *observers;
148 Efl_Observer_Iterator *it; 184 Efl_Observer_Iterator *it;
149 185
150 if (!pd->observers) return NULL; 186 if (!pd->observers) return NULL;
@@ -156,7 +192,7 @@ _efl_observable_observers_iterator_new(Eo *obj EINA_UNUSED, Efl_Observable_Data
156 if (!it) return NULL; 192 if (!it) return NULL;
157 193
158 EINA_MAGIC_SET(&it->iterator, EINA_MAGIC_ITERATOR); 194 EINA_MAGIC_SET(&it->iterator, EINA_MAGIC_ITERATOR);
159 it->classes = eina_hash_iterator_data_new(observers); 195 it->classes = eina_list_iterator_new(observers->list);
160 196
161 it->iterator.version = EINA_ITERATOR_VERSION; 197 it->iterator.version = EINA_ITERATOR_VERSION;
162 it->iterator.next = _efl_observable_observers_iterator_next; 198 it->iterator.next = _efl_observable_observers_iterator_next;