From b051e12c20a77d1b31a35c04a9767a954b635e0b Mon Sep 17 00:00:00 2001 From: L-diy Date: Thu, 16 Nov 2023 16:13:22 +0100 Subject: [PATCH] Calculate and cache the file count during llfs init --- project/Core/Src/llfs.c | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/project/Core/Src/llfs.c b/project/Core/Src/llfs.c index 31e1f1c..818051f 100644 --- a/project/Core/Src/llfs.c +++ b/project/Core/Src/llfs.c @@ -41,6 +41,14 @@ int8_t llfs_init(void) { file_table[STDOUT_FILENO] = stdout; file_table[STDERR_FILENO] = stderr; + // Calculate the number of files in the filesystem and cache it + const struct llfs_data_file* file = llfs_root; + file_count = 0; + while (file != NULL) { + file_count++; + file = file->next; + } + return 0; } @@ -130,13 +138,6 @@ llfs_file_t* llfs_next_file(void** mem, char* filter) { } size_t llfs_file_count(void) { - if (file_count == 0) { - const struct llfs_data_file* file = llfs_root; - while (file != NULL) { - file_count++; - file = file->next; - } - } return file_count; }