summaryrefslogtreecommitdiff
path: root/src/lib/ecore_wl2/ecore_wl2_input.c
diff options
context:
space:
mode:
authorChris Michael <cp.michael@samsung.com>2018-03-07 09:37:25 -0500
committerChris Michael <cp.michael@samsung.com>2018-03-07 09:37:25 -0500
commita1bb9b313f008f65b06319a1bede1f175c29d3da (patch)
treedc253235e7c67072b444c24020f4026c2d63c9c2 /src/lib/ecore_wl2/ecore_wl2_input.c
parent482c5d1ba237225720f02c358166291cbe9349ea (diff)
ecore-wl2: Reduce calls to strlen
Small patch to reduce calls to strlen when sending key events. This patch is loosely based on Phab D5567 @fix Signed-off-by: Chris Michael <cp.michael@samsung.com>
Diffstat (limited to 'src/lib/ecore_wl2/ecore_wl2_input.c')
-rw-r--r--src/lib/ecore_wl2/ecore_wl2_input.c15
1 files changed, 10 insertions, 5 deletions
diff --git a/src/lib/ecore_wl2/ecore_wl2_input.c b/src/lib/ecore_wl2/ecore_wl2_input.c
index 26d205de04..c252593350 100644
--- a/src/lib/ecore_wl2/ecore_wl2_input.c
+++ b/src/lib/ecore_wl2/ecore_wl2_input.c
@@ -625,6 +625,7 @@ _ecore_wl2_input_key_send(Ecore_Wl2_Input *input, Ecore_Wl2_Window *window, xkb_
625{ 625{
626 Ecore_Event_Key *ev; 626 Ecore_Event_Key *ev;
627 char key[256], keyname[256], compose[256]; 627 char key[256], keyname[256], compose[256];
628 int name_len, key_len, comp_len;
628 629
629 memset(key, 0, sizeof(key)); 630 memset(key, 0, sizeof(key));
630 memset(keyname, 0, sizeof(keyname)); 631 memset(keyname, 0, sizeof(keyname));
@@ -636,18 +637,22 @@ _ecore_wl2_input_key_send(Ecore_Wl2_Input *input, Ecore_Wl2_Window *window, xkb_
636 _ecore_wl2_input_key_translate(sym, input->keyboard.modifiers, 637 _ecore_wl2_input_key_translate(sym, input->keyboard.modifiers,
637 compose, sizeof(compose)); 638 compose, sizeof(compose));
638 639
639 ev = calloc(1, sizeof(Ecore_Event_Key) + strlen(key) + strlen(keyname) + 640 name_len = strlen(keyname);
640 ((compose[0] != '\0') ? strlen(compose) : 0) + 3); 641 key_len = strlen(key);
642 comp_len = strlen(compose);
643
644 ev = calloc(1, sizeof(Ecore_Event_Key) + key_len + name_len +
645 ((compose[0] != '\0') ? comp_len : 0) + 3);
641 if (!ev) return; 646 if (!ev) return;
642 647
643 ev->keyname = (char *)(ev + 1); 648 ev->keyname = (char *)(ev + 1);
644 ev->key = ev->keyname + strlen(keyname) + 1; 649 ev->key = ev->keyname + name_len + 1;
645 ev->compose = strlen(compose) ? ev->key + strlen(key) + 1 : NULL; 650 ev->compose = comp_len ? ev->key + key_len + 1 : NULL;
646 ev->string = ev->compose; 651 ev->string = ev->compose;
647 652
648 strcpy((char *)ev->keyname, keyname); 653 strcpy((char *)ev->keyname, keyname);
649 strcpy((char *)ev->key, key); 654 strcpy((char *)ev->key, key);
650 if (strlen(compose)) strcpy((char *)ev->compose, compose); 655 if (comp_len) strcpy((char *)ev->compose, compose);
651 656
652 ev->window = window->id; 657 ev->window = window->id;
653 ev->event_window = window->id; 658 ev->event_window = window->id;