From 36f18d09617b063c3f38aa7c5c0d686471daab3b Mon Sep 17 00:00:00 2001 From: apocelipes Date: Mon, 27 Nov 2023 16:02:22 +0900 Subject: [PATCH] optimize(IO): speed up createSubfolders Avoiding unnecessary ffStrbufAppendC calls to speed up createSubfolders. Now it finds and adds a subdirectory at a time instead of just appending a char. --- src/common/io/io_unix.c | 10 +++++----- src/common/io/io_windows.c | 10 +++++----- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/common/io/io_unix.c b/src/common/io/io_unix.c index 0daf53ebcc..87831e3ed3 100644 --- a/src/common/io/io_unix.c +++ b/src/common/io/io_unix.c @@ -16,12 +16,12 @@ static void createSubfolders(const char* fileName) { FF_STRBUF_AUTO_DESTROY path = ffStrbufCreate(); - while(*fileName != '\0') + char *token = NULL; + while((token = strchr(fileName, '/')) != NULL) { - ffStrbufAppendC(&path, *fileName); - if(*fileName == '/') - mkdir(path.chars, S_IRWXU | S_IRGRP | S_IROTH); - ++fileName; + ffStrbufAppendNS(&path, (uint32_t)(token - fileName + 1), fileName); + mkdir(path.chars, S_IRWXU | S_IRGRP | S_IROTH); + fileName = token + 1; } } diff --git a/src/common/io/io_windows.c b/src/common/io/io_windows.c index d0d5bd1356..97f3c80452 100644 --- a/src/common/io/io_windows.c +++ b/src/common/io/io_windows.c @@ -6,12 +6,12 @@ static void createSubfolders(const char* fileName) { FF_STRBUF_AUTO_DESTROY path = ffStrbufCreate(); - while(*fileName != '\0') + char *token = NULL; + while((token = strchr(fileName, '/')) != NULL) { - ffStrbufAppendC(&path, *fileName); - if(*fileName == '/') - CreateDirectoryA(path.chars, NULL); - ++fileName; + ffStrbufAppendNS(&path, (uint32_t)(token - fileName + 1), fileName); + CreateDirectoryA(path.chars, NULL); + fileName = token + 1; } }