]> Kevux Git Server - fll/commitdiff
Update: Slightly reduce recursion cost for private_fl_directory_do_recurse().
authorKevin Day <kevin@kevux.org>
Thu, 27 Apr 2023 02:36:41 +0000 (21:36 -0500)
committerKevin Day <kevin@kevux.org>
Thu, 27 Apr 2023 02:36:41 +0000 (21:36 -0500)
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

index 67b1a53e6ffffaedd8df6bf9d24ee67fcd529699..eb34e16a704b46a7f0fb9817064ef67499c14329 100644 (file)
@@ -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) {