summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJosé Roberto de Souza <jose.souza@intel.com>2013-07-18 19:00:57 -0300
committerJosé Roberto de Souza <jose.souza@intel.com>2013-07-22 10:14:16 -0300
commitfe6dbda0e18743eba6568ac36cff643f15442c26 (patch)
treeec40d6922007671733dc89fea979cded6b7a03eb
parentae561346e43fc252f6676b48a3e4195b2f2eb075 (diff)
edje: Refactor signal callbacks flags
Share a byte with 2 matchs and use bitwise operations to read/write they states is not much readable and easily could lead a issues. Use a struct is much simpler and only will coast a half of byte per match.
Diffstat (limited to '')
-rw-r--r--ChangeLog4
-rw-r--r--src/lib/edje/edje_match.c4
-rw-r--r--src/lib/edje/edje_private.h14
-rw-r--r--src/lib/edje/edje_program.c5
-rw-r--r--src/lib/edje/edje_signal.c130
5 files changed, 46 insertions, 111 deletions
diff --git a/ChangeLog b/ChangeLog
index 9bf591140e..0fec98aae9 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,7 @@
12013-07-22 José Roberto de Souza
2
3 * Edje: Refactor signal callbacks flags
4
12013-07-19 Cedric Bail 52013-07-19 Cedric Bail
2 6
3 * Edje: add threshold to draggable part. 7 * Edje: add threshold to draggable part.
diff --git a/src/lib/edje/edje_match.c b/src/lib/edje/edje_match.c
index 4ebff50db0..573191fb4d 100644
--- a/src/lib/edje/edje_match.c
+++ b/src/lib/edje/edje_match.c
@@ -539,7 +539,7 @@ edje_match_callback_exec_check_finals(const Edje_Signals_Sources_Patterns *ssp,
539 cb = &matches[*e]; 539 cb = &matches[*e];
540 if (cb) 540 if (cb)
541 { 541 {
542 if ((prop) && _edje_signal_callback_prop(ed->callbacks->flags, *e)) continue; 542 if ((prop) && ed->callbacks->flags[*e].propagate) continue;
543 eina_array_push(&run, cb); 543 eina_array_push(&run, cb);
544 r = 2; 544 r = 2;
545 } 545 }
@@ -551,7 +551,7 @@ edje_match_callback_exec_check_finals(const Edje_Signals_Sources_Patterns *ssp,
551 { 551 {
552 int idx = cb - matches; 552 int idx = cb - matches;
553 553
554 if (_edje_signal_callback_run(ed->callbacks->flags, idx)) continue; 554 if (ed->callbacks->flags[idx].delete_me) continue;
555 555
556 cb->func((void*) ed->callbacks->custom_data[idx], ed->obj, sig, source); 556 cb->func((void*) ed->callbacks->custom_data[idx], ed->obj, sig, source);
557 if (_edje_block_break(ed)) 557 if (_edje_block_break(ed))
diff --git a/src/lib/edje/edje_private.h b/src/lib/edje/edje_private.h
index d2bb323f0c..20124b4656 100644
--- a/src/lib/edje/edje_private.h
+++ b/src/lib/edje/edje_private.h
@@ -334,6 +334,7 @@ typedef struct _Edje_Signal_Source_Char Edje_Signal_Source_Char;
334typedef struct _Edje_Text_Insert_Filter_Callback Edje_Text_Insert_Filter_Callback; 334typedef struct _Edje_Text_Insert_Filter_Callback Edje_Text_Insert_Filter_Callback;
335typedef struct _Edje_Markup_Filter_Callback Edje_Markup_Filter_Callback; 335typedef struct _Edje_Markup_Filter_Callback Edje_Markup_Filter_Callback;
336typedef struct _Edje_Signals_Sources_Patterns Edje_Signals_Sources_Patterns; 336typedef struct _Edje_Signals_Sources_Patterns Edje_Signals_Sources_Patterns;
337typedef struct _Edje_Signal_Callback_Flags Edje_Signal_Callback_Flags;
337typedef struct _Edje_Signal_Callback_Group Edje_Signal_Callback_Group; 338typedef struct _Edje_Signal_Callback_Group Edje_Signal_Callback_Group;
338typedef struct _Edje_Signal_Callback_Match Edje_Signal_Callback_Match; 339typedef struct _Edje_Signal_Callback_Match Edje_Signal_Callback_Match;
339typedef struct _Edje_Signal_Callback_Matches Edje_Signal_Callback_Matches; 340typedef struct _Edje_Signal_Callback_Matches Edje_Signal_Callback_Matches;
@@ -830,13 +831,20 @@ struct _Edje_Signal_Callback_Matches
830 Eina_Bool hashed : 1; 831 Eina_Bool hashed : 1;
831}; 832};
832 833
834struct _Edje_Signal_Callback_Flags
835{
836 Eina_Bool delete_me:1;
837 Eina_Bool just_added:1;
838 Eina_Bool propagate:1;
839};
840
833struct _Edje_Signal_Callback_Group 841struct _Edje_Signal_Callback_Group
834{ 842{
835 const Edje_Signal_Callback_Matches *matches; 843 const Edje_Signal_Callback_Matches *matches;
836 844
837 void **custom_data; 845 void **custom_data;
838 846
839 Eina_Bool *flags; /* 4 bits per custom data (delete_me, just_added, propagate) */ 847 Edje_Signal_Callback_Flags *flags;
840}; 848};
841 849
842/*----------*/ 850/*----------*/
@@ -1992,9 +2000,7 @@ void _edje_signals_sources_patterns_clean(Edje_Signals_Sources_Patterns *ssp);
1992 2000
1993const Edje_Signals_Sources_Patterns *_edje_signal_callback_patterns_ref(const Edje_Signal_Callback_Group *gp); 2001const Edje_Signals_Sources_Patterns *_edje_signal_callback_patterns_ref(const Edje_Signal_Callback_Group *gp);
1994void _edje_signal_callback_patterns_unref(const Edje_Signals_Sources_Patterns *essp); 2002void _edje_signal_callback_patterns_unref(const Edje_Signals_Sources_Patterns *essp);
1995Eina_Bool _edje_signal_callback_prop(const Eina_Bool *flags, int i); 2003void _edje_signal_callback_reset(Edje_Signal_Callback_Flags *flags, unsigned int length);
1996Eina_Bool _edje_signal_callback_run(const Eina_Bool *flags, unsigned int i);
1997void _edje_signal_callback_reset(Eina_Bool *flags, unsigned int length);
1998 2004
1999void _edje_signal_callback_free(const Edje_Signal_Callback_Group *gp); 2005void _edje_signal_callback_free(const Edje_Signal_Callback_Group *gp);
2000 2006
diff --git a/src/lib/edje/edje_program.c b/src/lib/edje/edje_program.c
index 9fd3179162..52335b9135 100644
--- a/src/lib/edje/edje_program.c
+++ b/src/lib/edje/edje_program.c
@@ -1444,9 +1444,8 @@ _edje_emit_cb(Edje *ed, const char *sig, const char *src, Edje_Message_Signal_Da
1444 1444
1445 EINA_INARRAY_FOREACH(match, i) 1445 EINA_INARRAY_FOREACH(match, i)
1446 { 1446 {
1447 if (_edje_signal_callback_run(ed->callbacks->flags, *i)) continue; 1447 if (ed->callbacks->flags[*i].delete_me) continue;
1448 if ((prop) && (_edje_signal_callback_prop(ed->callbacks->flags, 1448 if ((prop) && (ed->callbacks->flags[*i].propagate)) continue;
1449 *i))) continue;
1450 1449
1451 cb = &m->matches[*i]; 1450 cb = &m->matches[*i];
1452 1451
diff --git a/src/lib/edje/edje_signal.c b/src/lib/edje/edje_signal.c
index 4988891bb6..83d6d1943e 100644
--- a/src/lib/edje/edje_signal.c
+++ b/src/lib/edje/edje_signal.c
@@ -2,10 +2,6 @@
2 2
3#include "edje_private.h" 3#include "edje_private.h"
4 4
5#define _DELETE_ME 0x4
6#define _JUST_ADDED 0x2
7#define _PROPAGATE 0x1
8
9static Eina_Hash *signal_match = NULL; 5static Eina_Hash *signal_match = NULL;
10 6
11static unsigned int 7static unsigned int
@@ -145,7 +141,7 @@ _edje_signal_callback_unset(Edje_Signal_Callback_Group *gp, int idx)
145static void 141static void
146_edje_signal_callback_set(Edje_Signal_Callback_Group *gp, int idx, 142_edje_signal_callback_set(Edje_Signal_Callback_Group *gp, int idx,
147 const char *sig, const char *src, 143 const char *sig, const char *src,
148 Edje_Signal_Cb func, void *data, Eina_Bool flags) 144 Edje_Signal_Cb func, void *data, Edje_Signal_Callback_Flags flags)
149{ 145{
150 Edje_Signal_Callback_Match *m; 146 Edje_Signal_Callback_Match *m;
151 147
@@ -156,34 +152,19 @@ _edje_signal_callback_set(Edje_Signal_Callback_Group *gp, int idx,
156 152
157 gp->custom_data[idx] = data; 153 gp->custom_data[idx] = data;
158 154
159 gp->flags[idx >> 1] = (gp->flags[idx >> 1] & (0xF << (((idx & 1) ^ 1) * 4))) | 155 gp->flags[idx] = flags;
160 ((flags & 0xF) << ((idx & 1) * 4));
161}
162
163Eina_Bool
164_edje_signal_callback_prop(const Eina_Bool *flags, int i)
165{
166 Eina_Bool b;
167
168 b = flags[i >> 1];
169 return b & (_PROPAGATE << ((i & 1) * 4));
170} 156}
171 157
172static Edje_Signal_Callback_Group * 158static Edje_Signal_Callback_Group *
173_edje_signal_callback_grow(Edje_Signal_Callback_Group *gp) 159_edje_signal_callback_grow(Edje_Signal_Callback_Group *gp)
174{ 160{
175 Edje_Signal_Callback_Matches *tmp; 161 Edje_Signal_Callback_Matches *tmp;
176 unsigned int c;
177 162
178 tmp = (Edje_Signal_Callback_Matches*) gp->matches; 163 tmp = (Edje_Signal_Callback_Matches*) gp->matches;
179 tmp->matches_count++; 164 tmp->matches_count++;
180 tmp->matches = realloc(tmp->matches, sizeof (Edje_Signal_Callback_Match) * tmp->matches_count); 165 tmp->matches = realloc(tmp->matches, sizeof (Edje_Signal_Callback_Match) * tmp->matches_count);
181 gp->custom_data = realloc(gp->custom_data, sizeof (void*) * tmp->matches_count); 166 gp->custom_data = realloc(gp->custom_data, sizeof (void*) * tmp->matches_count);
182 167 gp->flags = realloc(gp->flags, sizeof (Edje_Signal_Callback_Flags) * tmp->matches_count);
183 c = ((tmp->matches_count >> 1) + (tmp->matches_count & 1));
184 gp->flags = realloc(gp->flags, sizeof (Eina_Bool) * c);
185 // We have just expanded by one char, set it to 0
186 if (tmp->matches_count & 1) gp->flags[tmp->matches_count >> 1] = 0;
187 168
188 return gp; 169 return gp;
189} 170}
@@ -195,6 +176,11 @@ _edje_signal_callback_push(const Edje_Signal_Callback_Group *cgp,
195{ 176{
196 Edje_Signal_Callback_Group *gp = (Edje_Signal_Callback_Group*) cgp; 177 Edje_Signal_Callback_Group *gp = (Edje_Signal_Callback_Group*) cgp;
197 unsigned int i; 178 unsigned int i;
179 Edje_Signal_Callback_Flags flags;
180
181 flags.delete_me = EINA_FALSE;
182 flags.just_added = EINA_TRUE;
183 flags.propagate = !!propagate;
198 184
199 // let's first try to see if we do find an empty matching stop 185 // let's first try to see if we do find an empty matching stop
200 for (i = 0; i < gp->matches->matches_count; i++) 186 for (i = 0; i < gp->matches->matches_count; i++)
@@ -202,15 +188,10 @@ _edje_signal_callback_push(const Edje_Signal_Callback_Group *cgp,
202 src == gp->matches->matches[i].source && 188 src == gp->matches->matches[i].source &&
203 func == gp->matches->matches[i].func) 189 func == gp->matches->matches[i].func)
204 { 190 {
205 Eina_Bool flags; 191 if (gp->flags[i].delete_me)
206
207 flags = gp->flags[i >> 1] & (0xF << ((i & 1) * 4));
208 if (flags & _DELETE_ME)
209 { 192 {
210 _edje_signal_callback_unset(gp, i); 193 _edje_signal_callback_unset(gp, i);
211 _edje_signal_callback_set(gp, i, 194 _edje_signal_callback_set(gp, i, sig, src, func, data, flags);
212 sig, src, func, data,
213 (((!!propagate) & 1) | _JUST_ADDED));
214 return; 195 return;
215 } 196 }
216 } 197 }
@@ -237,32 +218,19 @@ _edje_signal_callback_push(const Edje_Signal_Callback_Group *cgp,
237 } 218 }
238 219
239 // search an empty spot now 220 // search an empty spot now
240 for (i = 0; i < gp->matches->matches_count; i += 2) 221 for (i = 0; i < gp->matches->matches_count; i++)
241 if (gp->flags[i >> 1] & (_DELETE_ME | (_DELETE_ME << 4))) 222 if (gp->flags[i].delete_me)
242 { 223 {
243 if (gp->flags[i >> 1] & _DELETE_ME) 224 _edje_signal_callback_unset(gp, i);
244 { 225 _edje_signal_callback_set(gp, i, sig, src, func, data, flags);
245 _edje_signal_callback_unset(gp, i); 226 return;
246 _edje_signal_callback_set(gp, i,
247 sig, src, func, data,
248 (((!!propagate) & 1) | _JUST_ADDED));
249 return;
250 }
251 if (gp->flags[i >> 1] & (_DELETE_ME << 4))
252 {
253 _edje_signal_callback_unset(gp, i + 1);
254 _edje_signal_callback_set(gp, i + 1,
255 sig, src, func, data,
256 (((!!propagate) & 1) | _JUST_ADDED));
257 return;
258 }
259 } 227 }
260 228
261 _edje_signal_callback_grow(gp); 229 _edje_signal_callback_grow(gp);
262 230
263 // Set propagate and just_added flags 231 // Set propagate and just_added flags
264 _edje_signal_callback_set(gp, gp->matches->matches_count - 1, 232 _edje_signal_callback_set(gp, gp->matches->matches_count - 1,
265 sig, src, func, data, (((!!propagate) & 1) | _JUST_ADDED)); 233 sig, src, func, data, flags);
266 234
267 return; 235 return;
268} 236}
@@ -343,10 +311,7 @@ _edje_signal_callback_disable(const Edje_Signal_Callback_Group *cgp,
343 func == gp->matches->matches[i].func && 311 func == gp->matches->matches[i].func &&
344 gp->custom_data[i] == data) 312 gp->custom_data[i] == data)
345 { 313 {
346 Eina_Bool flags; 314 gp->flags[i].delete_me = EINA_TRUE;
347
348 flags = gp->flags[i >> 1] | (_DELETE_ME << ((i & 1) * 4));
349 gp->flags[i >> 1] = flags;
350 return gp->custom_data[i]; 315 return gp->custom_data[i];
351 } 316 }
352 } 317 }
@@ -359,10 +324,7 @@ _edje_signal_callback_disable(const Edje_Signal_Callback_Group *cgp,
359 src == gp->matches->matches[i].source && 324 src == gp->matches->matches[i].source &&
360 func == gp->matches->matches[i].func) 325 func == gp->matches->matches[i].func)
361 { 326 {
362 Eina_Bool flags; 327 gp->flags[i].delete_me = EINA_TRUE;
363
364 flags = gp->flags[i >> 1] | (_DELETE_ME << ((i & 1) * 4));
365 gp->flags[i >> 1] = flags;
366 return gp->custom_data[i]; 328 return gp->custom_data[i];
367 } 329 }
368 } 330 }
@@ -373,32 +335,22 @@ _edje_signal_callback_disable(const Edje_Signal_Callback_Group *cgp,
373 335
374static void 336static void
375_edje_signal_callback_move_last(Edje_Signal_Callback_Group *gp, 337_edje_signal_callback_move_last(Edje_Signal_Callback_Group *gp,
376 int i) 338 unsigned int i)
377{ 339{
378 Edje_Signal_Callback_Matches *m; 340 Edje_Signal_Callback_Matches *m;
379 int j; 341 unsigned int j;
380 342
381 m = (Edje_Signal_Callback_Matches*) gp->matches; 343 m = (Edje_Signal_Callback_Matches*) gp->matches;
382 344
383 for (j = (int) --m->matches_count; j > i; --j) 345 for (j = --m->matches_count; j > i; --j)
384 { 346 {
385 if (!(gp->flags[j >> 1] & (_DELETE_ME << ((j & 1) * 4)))) 347 if (!gp->flags[j].delete_me)
386 { 348 {
387 Eina_Bool flag_neighbor_i, flag_j;
388
389 _edje_signal_callback_unset(gp, i); 349 _edje_signal_callback_unset(gp, i);
390
391 m->matches[i].signal = m->matches[j].signal; 350 m->matches[i].signal = m->matches[j].signal;
392 m->matches[i].source = m->matches[j].source; 351 m->matches[i].source = m->matches[j].source;
393 m->matches[i].func = m->matches[j].func; 352 m->matches[i].func = m->matches[j].func;
394 353 gp->flags[i] = gp->flags[j];
395 flag_j = gp->flags[j >> 1] >> ((j & 1) * 4);
396 flag_neighbor_i = gp->flags[i >> 1] >> ((!(j & 1)) * 4);
397
398 if (i & 1)
399 gp->flags[i >> 1] = flag_neighbor_i | (flag_j << 4);
400 else
401 gp->flags[i >> 1] = flag_j | (flag_neighbor_i << 4);
402 return; 354 return;
403 } 355 }
404 } 356 }
@@ -421,23 +373,12 @@ _edje_signal_callback_patterns_ref(const Edje_Signal_Callback_Group *gp)
421 { 373 {
422 // Let compact it and remove uneeded pattern before building it 374 // Let compact it and remove uneeded pattern before building it
423 // We can do that because the custom data are kept local into the matching code. 375 // We can do that because the custom data are kept local into the matching code.
424 Eina_Bool delete_me = _DELETE_ME | (_DELETE_ME << 4);
425 unsigned int i; 376 unsigned int i;
426 377
427 for (i = 0; i < tmp->matches_count; i += 2) 378 for (i = 0; i < tmp->matches_count; i++)
428 { 379 {
429 if (gp->flags[i >> 1] & delete_me) 380 if (gp->flags[i].delete_me)
430 { 381 _edje_signal_callback_move_last((Edje_Signal_Callback_Group*) gp, i);
431 if (gp->flags[i >> 1] & _DELETE_ME)
432 {
433 _edje_signal_callback_move_last((Edje_Signal_Callback_Group*) gp, i);
434 }
435 if (i + 1 < gp->matches->matches_count &&
436 (gp->flags[i >> 1] & (_DELETE_ME << 4)))
437 {
438 _edje_signal_callback_move_last((Edje_Signal_Callback_Group*) gp, i + 1);
439 }
440 }
441 } 382 }
442 383
443 } 384 }
@@ -488,26 +429,11 @@ _edje_signal_callback_patterns_unref(const Edje_Signals_Sources_Patterns *essp)
488 } 429 }
489} 430}
490 431
491Eina_Bool
492_edje_signal_callback_run(const Eina_Bool *flags, unsigned int i)
493{
494 Eina_Bool r;
495
496 r = flags[i >> 1] & ((_DELETE_ME) << ((i & 0x1) * 4));
497
498 return r;
499}
500
501void 432void
502_edje_signal_callback_reset(Eina_Bool *flags, unsigned int length) 433_edje_signal_callback_reset(Edje_Signal_Callback_Flags *flags, unsigned int length)
503{ 434{
504 Eina_Bool mask;
505 unsigned int i; 435 unsigned int i;
506
507 mask = ~((_JUST_ADDED << 4) | _JUST_ADDED);
508
509 length >>= 1;
510 for (i = 0; i < length; ++i) 436 for (i = 0; i < length; ++i)
511 flags[i] &= mask; 437 flags[i].just_added = EINA_FALSE;
512} 438}
513 439