eventHandlerHook: Compute the one-shot index early

Instead of computing the one-shot index when it is needed, compute it once at
the beginning. Even if we don't use it, we still save a few bytes by not
computing it in two branches.

Signed-off-by: Gergely Nagy <algernon@madhouse-project.org>
pull/389/head
Gergely Nagy 7 years ago
parent 52c8402006
commit 87fbf85995

@ -81,7 +81,7 @@ void OneShot::cancelOneShot(uint8_t idx) {
} }
Key OneShot::eventHandlerHook(Key mapped_key, byte row, byte col, uint8_t key_state) { Key OneShot::eventHandlerHook(Key mapped_key, byte row, byte col, uint8_t key_state) {
uint8_t idx; uint8_t idx = mapped_key.raw - ranges::OS_FIRST;
if (key_state & INJECTED) if (key_state & INJECTED)
return mapped_key; return mapped_key;
@ -91,7 +91,6 @@ Key OneShot::eventHandlerHook(Key mapped_key, byte row, byte col, uint8_t key_st
return mapped_key; return mapped_key;
} }
idx = mapped_key.raw - ranges::OS_FIRST;
if (keyToggledOff(key_state)) { if (keyToggledOff(key_state)) {
clearPressed(idx); clearPressed(idx);
} else if (keyToggledOn(key_state)) { } else if (keyToggledOn(key_state)) {
@ -114,8 +113,6 @@ Key OneShot::eventHandlerHook(Key mapped_key, byte row, byte col, uint8_t key_st
return mapped_key; return mapped_key;
if (isOS(mapped_key)) { if (isOS(mapped_key)) {
idx = mapped_key.raw - ranges::OS_FIRST;
if (isSticky(idx)) { if (isSticky(idx)) {
if (keyToggledOn(key_state)) { // maybe on _off instead? if (keyToggledOn(key_state)) { // maybe on _off instead?
saveAsPrevious(mapped_key); saveAsPrevious(mapped_key);

Loading…
Cancel
Save