]> Kevux Git Server - fll/commitdiff
Update: Reduce memory usage by fl_fss_basic_content_read() in some circumstances.
authorKevin Day <Kevin@kevux.org>
Sun, 4 Aug 2024 06:07:22 +0000 (01:07 -0500)
committerKevin Day <Kevin@kevux.org>
Sun, 4 Aug 2024 06:07:22 +0000 (01:07 -0500)
The fl_fss_basic_content_read() is simple enough that the allocation of the found array is only needed on success.

level_1/fl_fss/c/fss/basic.c

index c6a4700224354cc5ed93eccac3acf010004c73ac..a8e2c45ea9cf6f9e5bb86c8c3123a9bc1df9176b 100644 (file)
@@ -40,11 +40,7 @@ extern "C" {
       return;
     }
 
-    state->status = f_memory_array_increase(state->step_small, sizeof(f_range_t), (void **) &found->array, &found->used, &found->size);
-    if (F_status_is_error(state->status)) return;
-
     const f_number_unsigned_t begin = range->start;
-    found->array[found->used].start = range->start;
 
     for (;; ++range->start) {
 
@@ -62,7 +58,11 @@ extern "C" {
 
     if (F_status_is_error(state->status)) return;
 
+    state->status = f_memory_array_increase(found->size ? found->size == 1 ? 4 : state->step_small : 1, sizeof(f_range_t), (void **) &found->array, &found->used, &found->size);
+    if (F_status_is_error(state->status)) return;
+
     if (range->start > begin) {
+      found->array[found->used].start = begin;
       found->array[found->used++].stop = range->start - 1;
     }
     else {