From 994cd52510f3f56dade92b4d6711740d2e6c58b7 Mon Sep 17 00:00:00 2001
From: Okke Formsma <okke@formsma.nl>
Date: Mon, 30 Nov 2020 22:18:03 +0100
Subject: [PATCH] refactor(sticky keys): use pointer to avoid repetition in
 store_sticky_key

---
 app/src/behaviors/behavior_sticky_key.c | 26 ++++++++++++-------------
 1 file changed, 13 insertions(+), 13 deletions(-)

diff --git a/app/src/behaviors/behavior_sticky_key.c b/app/src/behaviors/behavior_sticky_key.c
index 295d243b..776d3e2d 100644
--- a/app/src/behaviors/behavior_sticky_key.c
+++ b/app/src/behaviors/behavior_sticky_key.c
@@ -53,21 +53,21 @@ static struct active_sticky_key *store_sticky_key(uint32_t position, uint32_t pa
                                                   uint32_t param2,
                                                   const struct behavior_sticky_key_config *config) {
     for (int i = 0; i < ZMK_BHV_STICKY_KEY_MAX_HELD; i++) {
-        if (active_sticky_keys[i].position != ZMK_BHV_STICKY_KEY_POSITION_NOT_USED ||
-        if (active_sticky_keys[i].position != ZMK_BHV_STICKY_KEY_POSITION_FREE ||
-            active_sticky_keys[i].timer_cancelled) {
+        struct active_sticky_key *const sticky_key = &active_sticky_keys[i];
+        if (sticky_key->position != ZMK_BHV_STICKY_KEY_POSITION_FREE ||
+            sticky_key->timer_cancelled) {
             continue;
         }
-        active_sticky_keys[i].position = position;
-        active_sticky_keys[i].param1 = param1;
-        active_sticky_keys[i].param2 = param2;
-        active_sticky_keys[i].config = config;
-        active_sticky_keys[i].release_at = 0;
-        active_sticky_keys[i].timer_cancelled = false;
-        active_sticky_keys[i].timer_started = false;
-        active_sticky_keys[i].modified_key_usage_page = 0;
-        active_sticky_keys[i].modified_key_keycode = 0;
-        return &active_sticky_keys[i];
+        sticky_key->position = position;
+        sticky_key->param1 = param1;
+        sticky_key->param2 = param2;
+        sticky_key->config = config;
+        sticky_key->release_at = 0;
+        sticky_key->timer_cancelled = false;
+        sticky_key->timer_started = false;
+        sticky_key->modified_key_usage_page = 0;
+        sticky_key->modified_key_keycode = 0;
+        return sticky_key;
     }
     return NULL;
 }