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

Loading…
Cancel
Save