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 <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 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68
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->mods.mask & mod_mask) {
+ state->components.leds |= (1u << idx);
+ continue;
+ }
+ }
- 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->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)
+ if (led->ctrls & state->keymap->enabled_ctrls) {
state->components.leds |= (1u << idx);
+ continue;
+ }
}
}