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.
This commit is contained in:
apocelipes
2023-11-27 16:02:22 +09:00
committed by Carter Li
parent e67a6856ce
commit 36f18d0961
2 changed files with 10 additions and 10 deletions
+5 -5
View File
@@ -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;
}
}
+5 -5
View File
@@ -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;
}
}