Speed up Layer.lookup considerably

Instead of always iterating through all layers, which slows us down
considerably, keep track of the highest active one, and start from there.

This has a VERY noticeable impact on the speed at which we finish a scan cycle.

Signed-off-by: Gergely Nagy <algernon@madhouse-project.org>
pull/103/head
Gergely Nagy 8 years ago
parent ae9264924d
commit 4b110b517d

@ -4,6 +4,8 @@
static uint8_t DefaultLayer; static uint8_t DefaultLayer;
static uint32_t LayerState; static uint32_t LayerState;
uint8_t Layer_::highestLayer;
static void handle_keymap_key_event(Key keymapEntry, uint8_t keyState) { static void handle_keymap_key_event(Key keymapEntry, uint8_t keyState) {
if (keymapEntry.keyCode >= MOMENTARY_OFFSET) { if (keymapEntry.keyCode >= MOMENTARY_OFFSET) {
uint8_t target = keymapEntry.keyCode - MOMENTARY_OFFSET; uint8_t target = keymapEntry.keyCode - MOMENTARY_OFFSET;
@ -51,7 +53,7 @@ Layer_::Layer_ (void) {
Key Layer_::lookup(byte row, byte col) { Key Layer_::lookup(byte row, byte col) {
Key mappedKey; Key mappedKey;
int8_t layer = 31; int8_t layer = highestLayer;
mappedKey.raw = Key_Transparent.raw; mappedKey.raw = Key_Transparent.raw;
@ -80,10 +82,14 @@ void Layer_::move (uint8_t layer) {
void Layer_::on (uint8_t layer) { void Layer_::on (uint8_t layer) {
bitSet (LayerState, layer); bitSet (LayerState, layer);
if (layer > highestLayer)
highestLayer = layer;
} }
void Layer_::off (uint8_t layer) { void Layer_::off (uint8_t layer) {
bitClear (LayerState, layer); bitClear (LayerState, layer);
if (layer == highestLayer)
highestLayer = top();
} }
boolean Layer_::isOn (uint8_t layer) { boolean Layer_::isOn (uint8_t layer) {

@ -25,6 +25,9 @@ class Layer_ {
static uint32_t getLayerState(void); static uint32_t getLayerState(void);
static Key eventHandler(Key mappedKey, byte row, byte col, uint8_t keyState); static Key eventHandler(Key mappedKey, byte row, byte col, uint8_t keyState);
private:
static uint8_t highestLayer;
}; };
extern Layer_ Layer; extern Layer_ Layer;

Loading…
Cancel
Save