summaryrefslogtreecommitdiff
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
parent561481f6ad0cf9c5c12ee5c6091625120ad4da11 (diff)
downloadefl-8e2e7bd61e102e8e56dd6e2d605548c0856e2a88.tar.gz
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
-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 66be6ff96b..9bfc060d14 100644
--- a/src/lib/eo/Eo.h
+++ b/src/lib/eo/Eo.h
@@ -249,7 +249,7 @@ typedef unsigned int Eo_Op;
* @param name The name of the event.
* @see Eo_Event_Description
*/
-#define EO_EVENT_DESCRIPTION(name) { name, EINA_FALSE }
+#define EO_EVENT_DESCRIPTION(name) { name, EINA_FALSE, EINA_FALSE }
/**
* @def EO_EVENT_DESCRIPTION_HOT(name)
@@ -259,7 +259,7 @@ typedef unsigned int Eo_Op;
* @see Eo_Event_Description
* @see EO_EVENT_DESCRIPTION
*/
-#define EO_EVENT_DESCRIPTION_HOT(name) { name, EINA_TRUE }
+#define EO_EVENT_DESCRIPTION_HOT(name) { name, EINA_TRUE, EINA_FALSE }
diff --git a/src/lib/eo/eo_base.eo b/src/lib/eo/eo_base.eo
index fbce01c7a9..f16813783d 100644
--- a/src/lib/eo/eo_base.eo
+++ b/src/lib/eo/eo_base.eo
@@ -7,6 +7,7 @@ struct Eo.Event_Description {
[[This struct holds the description of a specific event.]]
name: const(char) *; [[name of the event.]]
unfreezable: bool; [[Eina_True if the event cannot be frozen.]]
+ legacy_is: bool; [[Internal use: if is a legacy event.]]
}
struct Eo.Callback_Array_Item {
diff --git a/src/lib/eo/eo_base_class.c b/src/lib/eo/eo_base_class.c
index f0a4030af3..99c348d0f5 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)
/* XXX: Legacy support, remove when legacy is dead. */
static Eina_Hash *_legacy_events_hash = NULL;
-#define _LEGACY_EVENT_FIRST_CHAR 1
EAPI const Eo_Event_Description *
eo_base_legacy_only_event_description_get(const char *_event_name)
{
char buf[1024];
- buf[0] = _LEGACY_EVENT_FIRST_CHAR; /* Encode it's a legacy event */
- strncpy(buf + 1, _event_name, sizeof(buf) - 1);
+ strncpy(buf, _event_name, sizeof(buf) - 1);
buf[sizeof(buf) - 1] = '\0';
Eina_Stringshare *event_name = eina_stringshare_add(buf);
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)
{
event_desc = calloc(1, sizeof(Eo_Event_Description));
event_desc->name = event_name;
+ event_desc->legacy_is = EINA_TRUE;
eina_hash_add(_legacy_events_hash, event_name, event_desc);
}
else
@@ -426,24 +425,10 @@ eo_base_legacy_only_event_description_get(const char *_event_name)
return event_desc;
}
-static Eina_Bool
+static inline Eina_Bool
_legacy_event_desc_is(const Eo_Event_Description *desc)
{
- return (desc->name[0] == _LEGACY_EVENT_FIRST_CHAR);
-}
-
-/* Also supports non legacy. */
-static const char *
-_legacy_event_desc_name_get(const Eo_Event_Description *desc)
-{
- if (_legacy_event_desc_is(desc))
- {
- return desc->name + 1;
- }
- else
- {
- return desc->name;
- }
+ return desc->legacy_is;
}
static void
@@ -672,9 +657,7 @@ _cb_desc_match(const Eo_Event_Description *a, const Eo_Event_Description *b)
}
else if (_legacy_event_desc_is(a) || _legacy_event_desc_is(b))
{
- const char *aname = _legacy_event_desc_name_get(a);
- const char *bname = _legacy_event_desc_name_get(b);
- return !strcmp(aname, bname);
+ return !strcmp(a->name, b->name);
}
else
{
diff --git a/src/tests/eo/suite/eo_test_general.c b/src/tests/eo/suite/eo_test_general.c
index d8f929131c..394e9c0935 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)
{
const Eo_Event_Description *a_desc = eo_base_legacy_only_event_description_get("a,changed");
fail_if(!a_desc);
- ck_assert_str_eq(a_desc->name, "\x01" "a,changed");
+ ck_assert_str_eq(a_desc->name, "a,changed");
fail_if(a_desc == EV_A_CHANGED);
const Eo_Event_Description *bad_desc = eo_base_legacy_only_event_description_get("bad");
fail_if(!bad_desc);
- ck_assert_str_eq(bad_desc->name, "\x01" "bad");
+ ck_assert_str_eq(bad_desc->name, "bad");
/* Call Eo event with legacy and non-legacy callbacks. */
_eo_signals_cb_current = 0;