1
0
Fork 0

Optimization for scanning less layers. (#8311)

* Optimization for scanning less layers.

* Rename NUM_LAYERS to MAX_LAYER.
This commit is contained in:
Alex Ong 2020-05-11 10:04:38 +10:00 committed by GitHub
parent d15a60d2d3
commit 361ac2f32a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 3 deletions

View file

@ -257,7 +257,7 @@ uint8_t layer_switch_get_layer(keypos_t key) {
layer_state_t layers = layer_state | default_layer_state; layer_state_t layers = layer_state | default_layer_state;
/* check top layer first */ /* check top layer first */
for (int8_t i = sizeof(layer_state_t) * 8 - 1; i >= 0; i--) { for (int8_t i = MAX_LAYER - 1; i >= 0; i--) {
if (layers & (1UL << i)) { if (layers & (1UL << i)) {
action = action_for_key(i, key); action = action_for_key(i, key);
if (action.code != ACTION_TRANSPARENT) { if (action.code != ACTION_TRANSPARENT) {

View file

@ -23,12 +23,24 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#if defined(LAYER_STATE_8BIT) #if defined(LAYER_STATE_8BIT)
typedef uint8_t layer_state_t; typedef uint8_t layer_state_t;
# define MAX_LAYER_BITS 3
# ifndef MAX_LAYER
# define MAX_LAYER 8
# endif
# define get_highest_layer(state) biton(state) # define get_highest_layer(state) biton(state)
#elif defined(LAYER_STATE_16BIT) #elif defined(LAYER_STATE_16BIT)
typedef uint16_t layer_state_t; typedef uint16_t layer_state_t;
# define MAX_LAYER_BITS 4
# ifndef MAX_LAYER
# define MAX_LAYER 16
# endif
# define get_highest_layer(state) biton16(state) # define get_highest_layer(state) biton16(state)
#else #else
typedef uint32_t layer_state_t; typedef uint32_t layer_state_t;
# define MAX_LAYER_BITS 5
# ifndef MAX_LAYER
# define MAX_LAYER 32
# endif
# define get_highest_layer(state) biton32(state) # define get_highest_layer(state) biton32(state)
#endif #endif
@ -96,8 +108,7 @@ layer_state_t layer_state_set_kb(layer_state_t state);
/* pressed actions cache */ /* pressed actions cache */
#if !defined(NO_ACTION_LAYER) && !defined(STRICT_LAYER_RELEASE) #if !defined(NO_ACTION_LAYER) && !defined(STRICT_LAYER_RELEASE)
/* The number of bits needed to represent the layer number: log2(32). */
# define MAX_LAYER_BITS 5
void update_source_layers_cache(keypos_t key, uint8_t layer); void update_source_layers_cache(keypos_t key, uint8_t layer);
uint8_t read_source_layers_cache(keypos_t key); uint8_t read_source_layers_cache(keypos_t key);
#endif #endif