Smarter Layer.on / Layer.off

Only update the keymap cache if the layer state changed for real. If we turn a
layer that was already on, on again, we do not need to update. Same for turning
them off.

This results in a tiny speedup if we have code that calls `Layer.on()` or
`Layer.off()` often.

Signed-off-by: Gergely Nagy <algernon@madhouse-project.org>
pull/174/head
Gergely Nagy 7 years ago
parent 75fb3ac14a
commit b8f8c9b3d5

@ -103,22 +103,28 @@ void Layer_::move(uint8_t layer) {
} }
void Layer_::on(uint8_t layer) { void Layer_::on(uint8_t layer) {
bool wasOn = isOn(layer);
bitSet(LayerState, layer); bitSet(LayerState, layer);
if (layer > highestLayer) if (layer > highestLayer)
highestLayer = layer; highestLayer = layer;
// Update the key cache, so that if anything depends on knowing the active // Update the key cache, so that if anything depends on knowing the active
// layout, the layout will be in sync. // layout, the layout will be in sync.
if (!wasOn)
updateKeymapCache(); updateKeymapCache();
} }
void Layer_::off(uint8_t layer) { void Layer_::off(uint8_t layer) {
bool wasOn = isOn(layer);
bitClear(LayerState, layer); bitClear(LayerState, layer);
if (layer == highestLayer) if (layer == highestLayer)
highestLayer = top(); highestLayer = top();
// Update the key cache, so that if anything depends on knowing the active // Update the key cache, so that if anything depends on knowing the active
// layout, the layout will be in sync. // layout, the layout will be in sync.
if (wasOn)
updateKeymapCache(); updateKeymapCache();
} }

Loading…
Cancel
Save