Skip to content

Commit

Permalink
optimize(IO): speed up createSubfolders
Browse files Browse the repository at this point in the history
Avoiding unnecessary ffStrbufAppendC calls to speed up createSubfolders.

Now it finds and adds a subdirectory at a time instead of just appending a char.
  • Loading branch information
apocelipes authored and CarterLi committed Nov 27, 2023
1 parent e67a685 commit 36f18d0
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
10 changes: 5 additions & 5 deletions src/common/io/io_unix.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}

Expand Down
10 changes: 5 additions & 5 deletions src/common/io/io_windows.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}

Expand Down

0 comments on commit 36f18d0

Please sign in to comment.