state: optimize xkb_state_led_update_all()
authorRan Benita <ran234@gmail.com>
Sat, 8 Feb 2014 13:53:50 +0000 (15:53 +0200)
committerRan Benita <ran234@gmail.com>
Sat, 8 Feb 2014 13:57:22 +0000 (15:57 +0200)
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>
src/state.c

index bf90688..41372f5 100644 (file)
@@ -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;
+        }
     }
 }