state: no need for loop in xkb_state_update_mask() Signed-off-by: Ran Benita <ran234@gmail.com>
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
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);
-
- 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;
- }
+ /* Only include modifiers which exist in the keymap. */
+ mask = (xkb_mod_mask_t) ((1ull << xkb_keymap_num_mods(state->keymap)) - 1u);
+
+ 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;