From ab94b211d07197134d47e6766f9850f514778593 Mon Sep 17 00:00:00 2001 From: Kevin Day Date: Wed, 26 Apr 2023 21:36:41 -0500 Subject: [PATCH] Update: Slightly reduce recursion cost for private_fl_directory_do_recurse(). Make some constant structures static with the goal of reducing the cost of recursion. Using static should help avoid redeclaring these variables per execution. This should reduce memory for each recurse into the function. --- level_1/fl_directory/c/private-directory.c | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/level_1/fl_directory/c/private-directory.c b/level_1/fl_directory/c/private-directory.c index 67b1a53..eb34e16 100644 --- a/level_1/fl_directory/c/private-directory.c +++ b/level_1/fl_directory/c/private-directory.c @@ -51,12 +51,22 @@ extern "C" { uint8_t j = 0; const f_array_length_t used_original = recurse->path.used; - const uint8_t flag_actions[] = { + static const uint8_t flag_actions[] = { f_directory_recurse_do_flag_before_e, 0, f_directory_recurse_do_flag_after_e, }; + static const uint16_t flags[] = { + f_directory_recurse_do_flag_block_e, + f_directory_recurse_do_flag_character_e, + f_directory_recurse_do_flag_regular_e, + f_directory_recurse_do_flag_link_e, + f_directory_recurse_do_flag_fifo_e, + f_directory_recurse_do_flag_socket_e, + f_directory_recurse_do_flag_unknown_e, + }; + { f_string_dynamics_t * const list[] = { &recurse->listing.block, @@ -68,16 +78,6 @@ extern "C" { &recurse->listing.unknown, }; - const uint16_t flags[] = { - f_directory_recurse_do_flag_block_e, - f_directory_recurse_do_flag_character_e, - f_directory_recurse_do_flag_regular_e, - f_directory_recurse_do_flag_link_e, - f_directory_recurse_do_flag_fifo_e, - f_directory_recurse_do_flag_socket_e, - f_directory_recurse_do_flag_unknown_e, - }; - for (uint8_t k = 0; k < 7; ++k) { for (i = 0; i < list[k]->used; ++i) { -- 1.8.3.1