summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJean Guyomarc'h <jean.guyomarch@openwide.fr>2015-10-15 11:29:51 +0200
committerNicolas Aguirre <aguirre.nicolas@gmail.com>2015-11-10 08:32:49 +0100
commitc85f86741585541abc8030fd49eeab2ff52b9127 (patch)
tree4dc031aac51cf35f0f0d0b8fdb9d999ce3bf69aa
parentd12ded45d63e4c0c3d6873abcc61707b6971fc1a (diff)
ecore_x: factorize multiple calls to strlen()
-rw-r--r--src/lib/ecore_x/xlib/ecore_x_events.c13
1 files changed, 9 insertions, 4 deletions
diff --git a/src/lib/ecore_x/xlib/ecore_x_events.c b/src/lib/ecore_x/xlib/ecore_x_events.c
index a071d23a05..4d40181021 100644
--- a/src/lib/ecore_x/xlib/ecore_x_events.c
+++ b/src/lib/ecore_x/xlib/ecore_x_events.c
@@ -334,6 +334,7 @@ _ecore_key_press(int event,
334 KeySym sym; 334 KeySym sym;
335 XComposeStatus status; 335 XComposeStatus status;
336 int val; 336 int val;
337 int key_len, keyname_len, compose_len;
337 338
338 _ecore_x_last_event_mouse_move = 0; 339 _ecore_x_last_event_mouse_move = 0;
339 keyname = XKeysymToString(_ecore_x_XKeycodeToKeysym(xevent->display, 340 keyname = XKeysymToString(_ecore_x_XKeycodeToKeysym(xevent->display,
@@ -370,14 +371,18 @@ _ecore_key_press(int event,
370 if (!key) 371 if (!key)
371 key = keyname; 372 key = keyname;
372 373
373 e = calloc(1, sizeof(Ecore_Event_Key) + strlen(key) + strlen(keyname) + 374 key_len = strlen(key);
374 (compose ? strlen(compose) : 0) + 3); 375 keyname_len = strlen(keyname);
376 compose_len = (compose) ? strlen(compose) : 0;
377
378 e = calloc(1, sizeof(Ecore_Event_Key) + key_len + keyname_len +
379 compose_len + 3);
375 if (!e) 380 if (!e)
376 goto on_error; 381 goto on_error;
377 382
378 e->keyname = (char *)(e + 1); 383 e->keyname = (char *)(e + 1);
379 e->key = e->keyname + strlen(keyname) + 1; 384 e->key = e->keyname + keyname_len + 1;
380 e->compose = (compose) ? e->key + strlen(key) + 1 : NULL; 385 e->compose = (compose) ? e->key + key_len + 1 : NULL;
381 e->string = e->compose; 386 e->string = e->compose;
382 387
383 strcpy((char *)e->keyname, keyname); 388 strcpy((char *)e->keyname, keyname);