From 04bacf87ba0f91a4d4445c55565373830cb7ec4a Mon Sep 17 00:00:00 2001 From: Ran Benita Date: Sat, 8 Feb 2014 15:53:50 +0200 Subject: [PATCH] state: optimize xkb_state_led_update_all() Before: ran@ran:~/src/libxkbcommon$ ./test/bench-key-proc ran 20000000 iterations in 6.623018074s After: ran@ran:~/src/libxkbcommon$ ./test/bench-key-proc ran 20000000 iterations in 4.762291091s Not that anyone needs to process millions of keys per second... Signed-off-by: Ran Benita --- src/state.c | 54 ++++++++++++++++++++++++++++++++--------------------- 1 file changed, 33 insertions(+), 21 deletions(-) diff --git a/src/state.c b/src/state.c index bf90688..41372f5 100644 --- a/src/state.c +++ b/src/state.c @@ -622,30 +622,42 @@ xkb_state_led_update_all(struct xkb_state *state) xkb_mod_mask_t mod_mask = 0; xkb_layout_mask_t group_mask = 0; - if (led->which_mods & XKB_STATE_MODS_EFFECTIVE) - mod_mask |= state->components.mods; - if (led->which_mods & XKB_STATE_MODS_DEPRESSED) - mod_mask |= state->components.base_mods; - if (led->which_mods & XKB_STATE_MODS_LATCHED) - mod_mask |= state->components.latched_mods; - if (led->which_mods & XKB_STATE_MODS_LOCKED) - mod_mask |= state->components.locked_mods; - if (led->mods.mask & mod_mask) - state->components.leds |= (1u << idx); + if (led->which_mods != 0 && led->mods.mask != 0) { + if (led->which_mods & XKB_STATE_MODS_EFFECTIVE) + mod_mask |= state->components.mods; + if (led->which_mods & XKB_STATE_MODS_DEPRESSED) + mod_mask |= state->components.base_mods; + if (led->which_mods & XKB_STATE_MODS_LATCHED) + mod_mask |= state->components.latched_mods; + if (led->which_mods & XKB_STATE_MODS_LOCKED) + mod_mask |= state->components.locked_mods; - if (led->which_groups & XKB_STATE_LAYOUT_EFFECTIVE) - group_mask |= (1u << state->components.group); - if (led->which_groups & XKB_STATE_LAYOUT_DEPRESSED) - group_mask |= (1u << state->components.base_group); - if (led->which_groups & XKB_STATE_LAYOUT_LATCHED) - group_mask |= (1u << state->components.latched_group); - if (led->which_groups & XKB_STATE_LAYOUT_LOCKED) - group_mask |= (1u << state->components.locked_group); - if (led->groups & group_mask) - state->components.leds |= (1u << idx); + if (led->mods.mask & mod_mask) { + state->components.leds |= (1u << idx); + continue; + } + } - if (led->ctrls & state->keymap->enabled_ctrls) + if (led->which_groups != 0 && led->groups != 0) { + if (led->which_groups & XKB_STATE_LAYOUT_EFFECTIVE) + group_mask |= (1u << state->components.group); + if (led->which_groups & XKB_STATE_LAYOUT_DEPRESSED) + group_mask |= (1u << state->components.base_group); + if (led->which_groups & XKB_STATE_LAYOUT_LATCHED) + group_mask |= (1u << state->components.latched_group); + if (led->which_groups & XKB_STATE_LAYOUT_LOCKED) + group_mask |= (1u << state->components.locked_group); + + if (led->groups & group_mask) { + state->components.leds |= (1u << idx); + continue; + } + } + + if (led->ctrls & state->keymap->enabled_ctrls) { state->components.leds |= (1u << idx); + continue; + } } }