From 80ae8e61ffe0677369e9f5f865ffe3ae76541816 Mon Sep 17 00:00:00 2001 From: Ran Benita Date: Mon, 18 Aug 2014 20:08:25 +0300 Subject: [PATCH] state: no need for loop in xkb_state_update_mask() Signed-off-by: Ran Benita --- src/state.c | 21 ++++++--------------- 1 file changed, 6 insertions(+), 15 deletions(-) diff --git a/src/state.c b/src/state.c index 94545bc..03463c8 100644 --- a/src/state.c +++ b/src/state.c @@ -786,25 +786,16 @@ xkb_state_update_mask(struct xkb_state *state, xkb_layout_index_t locked_group) { struct state_components prev_components; - xkb_mod_index_t num_mods; - xkb_mod_index_t idx; + xkb_mod_mask_t mask; prev_components = state->components; - state->components.base_mods = 0; - state->components.latched_mods = 0; - state->components.locked_mods = 0; - num_mods = xkb_keymap_num_mods(state->keymap); + /* Only include modifiers which exist in the keymap. */ + mask = (xkb_mod_mask_t) ((1ull << xkb_keymap_num_mods(state->keymap)) - 1u); - for (idx = 0; idx < num_mods; idx++) { - xkb_mod_mask_t mod = (1u << idx); - if (base_mods & mod) - state->components.base_mods |= mod; - if (latched_mods & mod) - state->components.latched_mods |= mod; - if (locked_mods & mod) - state->components.locked_mods |= mod; - } + state->components.base_mods = base_mods & mask; + state->components.latched_mods = latched_mods & mask; + state->components.locked_mods = locked_mods & mask; state->components.base_group = base_group; state->components.latched_group = latched_group;