Use __builtin_popcountl() in pressedKeyswitchCount()

Instead of iterating through all the bits, use `__builtin_popcountl()`, provided
by gcc, which should be considerably more efficient.

Fixes #27.

Signed-off-by: Gergely Nagy <algernon@keyboard.io>
pull/365/head
Gergely Nagy 6 years ago
parent 88ef2cfe3a
commit 7603cc813e

@ -273,13 +273,7 @@ bool Model01::isKeyswitchPressed(uint8_t keyIndex) {
}
uint8_t Model01::pressedKeyswitchCount() {
uint8_t count = 0;
for (uint8_t i = 0; i < 32; i++) {
count += bitRead(leftHandState.all, i) + bitRead(rightHandState.all, i);
}
return count;
return __builtin_popcountl(leftHandState.all) + __builtin_popcountl(rightHandState.all);
}
HARDWARE_IMPLEMENTATION KeyboardHardware;

Loading…
Cancel
Save