From 1a954e8da5dcbd81eeccb9d6ac41b6eda64d7b85 Mon Sep 17 00:00:00 2001 From: Stephen Ostermiller Date: Sun, 23 Nov 2025 06:32:36 -0500 Subject: Reduce tap dance memory usage, move state out of data (#25415) * Use less tap dance memory. Use dynamically allocated sparse array for tap dance state, dynamically allocate tap dance state when needed and free it when the tap dance is done. * new approach * Use null, check for null * Reformat with docker * Use uint8 with idx rather than uint16 with keycode in state * fix accidental change * reformat * Add null check * add documentation tip suggested by tzarc * Only allow tap dance state allocation on key down, not on key up Co-authored-by: Sergey Vlasov * Only allow tap dance allocation on key down, not on key up Co-authored-by: Sergey Vlasov * add user action required section --------- Co-authored-by: Sergey Vlasov --- tests/tap_dance/examples.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'tests') diff --git a/tests/tap_dance/examples.c b/tests/tap_dance/examples.c index 4b6bdb2090..6aaf008232 100644 --- a/tests/tap_dance/examples.c +++ b/tests/tap_dance/examples.c @@ -81,11 +81,13 @@ typedef struct { bool process_record_user(uint16_t keycode, keyrecord_t *record) { tap_dance_action_t *action; + tap_dance_state_t* state; switch (keycode) { case TD(CT_CLN): action = tap_dance_get(QK_TAP_DANCE_GET_INDEX(keycode)); - if (!record->event.pressed && action->state.count && !action->state.finished) { + state = tap_dance_get_state(QK_TAP_DANCE_GET_INDEX(keycode)); + if (!record->event.pressed && state != NULL && state->count && !state->finished) { tap_dance_tap_hold_t *tap_hold = (tap_dance_tap_hold_t *)action->user_data; tap_code16(tap_hold->tap); } -- cgit v1.2.3