From 77b01a668b2dbf53455e31a2a53a7cf6ee94a68a Mon Sep 17 00:00:00 2001 From: apocelipes Date: Sat, 9 Nov 2024 21:48:18 +0800 Subject: [PATCH] IO: optimize createSubfolders --- src/common/io/io_unix.c | 9 +++++---- src/common/io/io_windows.c | 8 +++++--- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/src/common/io/io_unix.c b/src/common/io/io_unix.c index 4cb946d0e8..d66354481b 100644 --- a/src/common/io/io_unix.c +++ b/src/common/io/io_unix.c @@ -23,13 +23,14 @@ static void createSubfolders(const char* fileName) { - FF_STRBUF_AUTO_DESTROY path = ffStrbufCreate(); - + char path[PATH_MAX]; char *token = NULL; + char *pathTail = path; while((token = strchr(fileName, '/')) != NULL) { - ffStrbufAppendNS(&path, (uint32_t)(token - fileName + 1), fileName); - mkdir(path.chars, S_IRWXU | S_IRGRP | S_IROTH); + uint32_t length = (uint32_t)(token - fileName + 1); + pathTail = ffStrCopyN(pathTail, fileName, length); + mkdir(path, 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 9f1a96ce53..90f12b76a6 100644 --- a/src/common/io/io_windows.c +++ b/src/common/io/io_windows.c @@ -8,12 +8,14 @@ static void createSubfolders(const char* fileName) { - FF_STRBUF_AUTO_DESTROY path = ffStrbufCreate(); + char path[MAX_PATH]; char *token = NULL; + char *pathTail = path; while((token = strchr(fileName, '/')) != NULL) { - ffStrbufAppendNS(&path, (uint32_t)(token - fileName + 1), fileName); - CreateDirectoryA(path.chars, NULL); + uint32_t length = (uint32_t)(token - fileName + 1); + pathTail = ffStrCopyN(pathTail, fileName, length); + CreateDirectoryA(path, NULL); fileName = token + 1; } }