From 6e43a233125594def49b38edca93424e3e1fc0bd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E3=83=95=E3=82=A3=E3=83=AB=E3=82=BF=E3=83=BC=E3=83=9A?= =?UTF-8?q?=E3=83=BC=E3=83=91=E3=83=BC?= <76888457+filterpaper@users.noreply.github.com> Date: Wed, 23 Jul 2025 13:11:22 +0800 Subject: [PATCH] Replace debounce malloc+loop with calloc * Replace malloc() with calloc() * Eliminate zero-initialization loops * Minor code spacing edit --- quantum/debounce/asym_eager_defer_pk.c | 8 +------- quantum/debounce/sym_defer_pk.c | 8 +------- quantum/debounce/sym_defer_pr.c | 3 +-- quantum/debounce/sym_eager_pk.c | 8 +------- quantum/debounce/sym_eager_pr.c | 5 +---- 5 files changed, 5 insertions(+), 27 deletions(-) diff --git a/quantum/debounce/asym_eager_defer_pk.c b/quantum/debounce/asym_eager_defer_pk.c index b6fcdc3d4e7..c9007e2130a 100644 --- a/quantum/debounce/asym_eager_defer_pk.c +++ b/quantum/debounce/asym_eager_defer_pk.c @@ -64,13 +64,7 @@ static void transfer_matrix_values(matrix_row_t raw[], matrix_row_t cooked[], ui // we use num_rows rather than MATRIX_ROWS to support split keyboards void debounce_init(uint8_t num_rows) { - debounce_counters = malloc(num_rows * MATRIX_COLS * sizeof(debounce_counter_t)); - int i = 0; - for (uint8_t r = 0; r < num_rows; r++) { - for (uint8_t c = 0; c < MATRIX_COLS; c++) { - debounce_counters[i++].time = DEBOUNCE_ELAPSED; - } - } + debounce_counters = calloc(num_rows * MATRIX_COLS, sizeof(debounce_counter_t)); } void debounce_free(void) { diff --git a/quantum/debounce/sym_defer_pk.c b/quantum/debounce/sym_defer_pk.c index 156535a3733..e8f9016f32b 100644 --- a/quantum/debounce/sym_defer_pk.c +++ b/quantum/debounce/sym_defer_pk.c @@ -56,13 +56,7 @@ static void start_debounce_counters(matrix_row_t raw[], matrix_row_t cooked[], u // we use num_rows rather than MATRIX_ROWS to support split keyboards void debounce_init(uint8_t num_rows) { - debounce_counters = (debounce_counter_t *)malloc(num_rows * MATRIX_COLS * sizeof(debounce_counter_t)); - int i = 0; - for (uint8_t r = 0; r < num_rows; r++) { - for (uint8_t c = 0; c < MATRIX_COLS; c++) { - debounce_counters[i++] = DEBOUNCE_ELAPSED; - } - } + debounce_counters = calloc(num_rows * MATRIX_COLS, sizeof(debounce_counter_t)); } void debounce_free(void) { diff --git a/quantum/debounce/sym_defer_pr.c b/quantum/debounce/sym_defer_pr.c index d6222af5b29..f93904bb03d 100644 --- a/quantum/debounce/sym_defer_pr.c +++ b/quantum/debounce/sym_defer_pr.c @@ -34,8 +34,7 @@ static matrix_row_t* last_raw; void debounce_init(uint8_t num_rows) { countdowns = (uint8_t*)calloc(num_rows, sizeof(uint8_t)); last_raw = (matrix_row_t*)calloc(num_rows, sizeof(matrix_row_t)); - - last_time = timer_read(); + last_time = timer_read(); } void debounce_free(void) { diff --git a/quantum/debounce/sym_eager_pk.c b/quantum/debounce/sym_eager_pk.c index b359e79287e..337de41a345 100644 --- a/quantum/debounce/sym_eager_pk.c +++ b/quantum/debounce/sym_eager_pk.c @@ -57,13 +57,7 @@ static void transfer_matrix_values(matrix_row_t raw[], matrix_row_t cooked[], ui // we use num_rows rather than MATRIX_ROWS to support split keyboards void debounce_init(uint8_t num_rows) { - debounce_counters = (debounce_counter_t *)malloc(num_rows * MATRIX_COLS * sizeof(debounce_counter_t)); - int i = 0; - for (uint8_t r = 0; r < num_rows; r++) { - for (uint8_t c = 0; c < MATRIX_COLS; c++) { - debounce_counters[i++] = DEBOUNCE_ELAPSED; - } - } + debounce_counters = calloc(num_rows * MATRIX_COLS, sizeof(debounce_counter_t)); } void debounce_free(void) { diff --git a/quantum/debounce/sym_eager_pr.c b/quantum/debounce/sym_eager_pr.c index 6cd9308affc..9450f51cbc4 100644 --- a/quantum/debounce/sym_eager_pr.c +++ b/quantum/debounce/sym_eager_pr.c @@ -56,10 +56,7 @@ static void transfer_matrix_values(matrix_row_t raw[], matrix_row_t cooked[], ui // we use num_rows rather than MATRIX_ROWS to support split keyboards void debounce_init(uint8_t num_rows) { - debounce_counters = (debounce_counter_t *)malloc(num_rows * sizeof(debounce_counter_t)); - for (uint8_t r = 0; r < num_rows; r++) { - debounce_counters[r] = DEBOUNCE_ELAPSED; - } + debounce_counters = calloc(num_rows, sizeof(debounce_counter_t)); } void debounce_free(void) {