summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorTom Hacohen <tom@stosb.com>2015-10-16 11:42:37 +0100
committerTom Hacohen <tom@stosb.com>2015-10-16 11:55:07 +0100
commit8e2e7bd61e102e8e56dd6e2d605548c0856e2a88 (patch)
treeafc6908356306e9b410e5d055a2052de0da829ce /src
parent561481f6ad0cf9c5c12ee5c6091625120ad4da11 (diff)
Eo events: Add a struct member marking if it's a legacy event or not.
My previous patch to this piece of code (37f84b7e966372384e2dfe5d191a6f907a17962e), caused a significant performance regression. This is such a hot path, that even accessing the strings when we don't have to slows things down drastically. It makes more sense to just store it in the structure. This commit breaks ABI (though most people probably won't even need to recompile anything else because of the memory layout). It was discussed on IRC and was decided this is a big enough issue to warrant a fix during the freeze. @fix
Diffstat (limited to 'src')
-rw-r--r--src/lib/eo/Eo.h4
-rw-r--r--src/lib/eo/eo_base.eo1
-rw-r--r--src/lib/eo/eo_base_class.c27
-rw-r--r--src/tests/eo/suite/eo_test_general.c4
4 files changed, 10 insertions, 26 deletions
diff --git a/src/lib/eo/Eo.h b/src/lib/eo/Eo.h
index 66be6ff..9bfc060 100644
--- a/src/lib/eo/Eo.h
+++ b/src/lib/eo/Eo.h
@@ -249,7 +249,7 @@ typedef unsigned int Eo_Op;
249 * @param name The name of the event. 249 * @param name The name of the event.
250 * @see Eo_Event_Description 250 * @see Eo_Event_Description
251 */ 251 */
252#define EO_EVENT_DESCRIPTION(name) { name, EINA_FALSE } 252#define EO_EVENT_DESCRIPTION(name) { name, EINA_FALSE, EINA_FALSE }
253 253
254/** 254/**
255 * @def EO_EVENT_DESCRIPTION_HOT(name) 255 * @def EO_EVENT_DESCRIPTION_HOT(name)
@@ -259,7 +259,7 @@ typedef unsigned int Eo_Op;
259 * @see Eo_Event_Description 259 * @see Eo_Event_Description
260 * @see EO_EVENT_DESCRIPTION 260 * @see EO_EVENT_DESCRIPTION
261 */ 261 */
262#define EO_EVENT_DESCRIPTION_HOT(name) { name, EINA_TRUE } 262#define EO_EVENT_DESCRIPTION_HOT(name) { name, EINA_TRUE, EINA_FALSE }
263 263
264 264
265 265
diff --git a/src/lib/eo/eo_base.eo b/src/lib/eo/eo_base.eo
index fbce01c..f168137 100644
--- a/src/lib/eo/eo_base.eo
+++ b/src/lib/eo/eo_base.eo
@@ -7,6 +7,7 @@ struct Eo.Event_Description {
7 [[This struct holds the description of a specific event.]] 7 [[This struct holds the description of a specific event.]]
8 name: const(char) *; [[name of the event.]] 8 name: const(char) *; [[name of the event.]]
9 unfreezable: bool; [[Eina_True if the event cannot be frozen.]] 9 unfreezable: bool; [[Eina_True if the event cannot be frozen.]]
10 legacy_is: bool; [[Internal use: if is a legacy event.]]
10} 11}
11 12
12struct Eo.Callback_Array_Item { 13struct Eo.Callback_Array_Item {
diff --git a/src/lib/eo/eo_base_class.c b/src/lib/eo/eo_base_class.c
index f0a4030..99c348d 100644
--- a/src/lib/eo/eo_base_class.c
+++ b/src/lib/eo/eo_base_class.c
@@ -401,14 +401,12 @@ _wref_destruct(Eo_Base_Data *pd)
401 401
402/* XXX: Legacy support, remove when legacy is dead. */ 402/* XXX: Legacy support, remove when legacy is dead. */
403static Eina_Hash *_legacy_events_hash = NULL; 403static Eina_Hash *_legacy_events_hash = NULL;
404#define _LEGACY_EVENT_FIRST_CHAR 1
405 404
406EAPI const Eo_Event_Description * 405EAPI const Eo_Event_Description *
407eo_base_legacy_only_event_description_get(const char *_event_name) 406eo_base_legacy_only_event_description_get(const char *_event_name)
408{ 407{
409 char buf[1024]; 408 char buf[1024];
410 buf[0] = _LEGACY_EVENT_FIRST_CHAR; /* Encode it's a legacy event */ 409 strncpy(buf, _event_name, sizeof(buf) - 1);
411 strncpy(buf + 1, _event_name, sizeof(buf) - 1);
412 buf[sizeof(buf) - 1] = '\0'; 410 buf[sizeof(buf) - 1] = '\0';
413 Eina_Stringshare *event_name = eina_stringshare_add(buf); 411 Eina_Stringshare *event_name = eina_stringshare_add(buf);
414 Eo_Event_Description *event_desc = eina_hash_find(_legacy_events_hash, event_name); 412 Eo_Event_Description *event_desc = eina_hash_find(_legacy_events_hash, event_name);
@@ -416,6 +414,7 @@ eo_base_legacy_only_event_description_get(const char *_event_name)
416 { 414 {
417 event_desc = calloc(1, sizeof(Eo_Event_Description)); 415 event_desc = calloc(1, sizeof(Eo_Event_Description));
418 event_desc->name = event_name; 416 event_desc->name = event_name;
417 event_desc->legacy_is = EINA_TRUE;
419 eina_hash_add(_legacy_events_hash, event_name, event_desc); 418 eina_hash_add(_legacy_events_hash, event_name, event_desc);
420 } 419 }
421 else 420 else
@@ -426,24 +425,10 @@ eo_base_legacy_only_event_description_get(const char *_event_name)
426 return event_desc; 425 return event_desc;
427} 426}
428 427
429static Eina_Bool 428static inline Eina_Bool
430_legacy_event_desc_is(const Eo_Event_Description *desc) 429_legacy_event_desc_is(const Eo_Event_Description *desc)
431{ 430{
432 return (desc->name[0] == _LEGACY_EVENT_FIRST_CHAR); 431 return desc->legacy_is;
433}
434
435/* Also supports non legacy. */
436static const char *
437_legacy_event_desc_name_get(const Eo_Event_Description *desc)
438{
439 if (_legacy_event_desc_is(desc))
440 {
441 return desc->name + 1;
442 }
443 else
444 {
445 return desc->name;
446 }
447} 432}
448 433
449static void 434static void
@@ -672,9 +657,7 @@ _cb_desc_match(const Eo_Event_Description *a, const Eo_Event_Description *b)
672 } 657 }
673 else if (_legacy_event_desc_is(a) || _legacy_event_desc_is(b)) 658 else if (_legacy_event_desc_is(a) || _legacy_event_desc_is(b))
674 { 659 {
675 const char *aname = _legacy_event_desc_name_get(a); 660 return !strcmp(a->name, b->name);
676 const char *bname = _legacy_event_desc_name_get(b);
677 return !strcmp(aname, bname);
678 } 661 }
679 else 662 else
680 { 663 {
diff --git a/src/tests/eo/suite/eo_test_general.c b/src/tests/eo/suite/eo_test_general.c
index d8f9291..394e9c0 100644
--- a/src/tests/eo/suite/eo_test_general.c
+++ b/src/tests/eo/suite/eo_test_general.c
@@ -125,12 +125,12 @@ START_TEST(eo_signals)
125 { 125 {
126 const Eo_Event_Description *a_desc = eo_base_legacy_only_event_description_get("a,changed"); 126 const Eo_Event_Description *a_desc = eo_base_legacy_only_event_description_get("a,changed");
127 fail_if(!a_desc); 127 fail_if(!a_desc);
128 ck_assert_str_eq(a_desc->name, "\x01" "a,changed"); 128 ck_assert_str_eq(a_desc->name, "a,changed");
129 fail_if(a_desc == EV_A_CHANGED); 129 fail_if(a_desc == EV_A_CHANGED);
130 130
131 const Eo_Event_Description *bad_desc = eo_base_legacy_only_event_description_get("bad"); 131 const Eo_Event_Description *bad_desc = eo_base_legacy_only_event_description_get("bad");
132 fail_if(!bad_desc); 132 fail_if(!bad_desc);
133 ck_assert_str_eq(bad_desc->name, "\x01" "bad"); 133 ck_assert_str_eq(bad_desc->name, "bad");
134 134
135 /* Call Eo event with legacy and non-legacy callbacks. */ 135 /* Call Eo event with legacy and non-legacy callbacks. */
136 _eo_signals_cb_current = 0; 136 _eo_signals_cb_current = 0;