Skip to content

Commit 0284e4c

Browse files
authored
IO: optimize createSubfolders (#1382)
1 parent 837903e commit 0284e4c

File tree

2 files changed

+10
-7
lines changed

2 files changed

+10
-7
lines changed

src/common/io/io_unix.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,14 @@
2323

2424
static void createSubfolders(const char* fileName)
2525
{
26-
FF_STRBUF_AUTO_DESTROY path = ffStrbufCreate();
27-
26+
char path[PATH_MAX];
2827
char *token = NULL;
28+
char *pathTail = path;
2929
while((token = strchr(fileName, '/')) != NULL)
3030
{
31-
ffStrbufAppendNS(&path, (uint32_t)(token - fileName + 1), fileName);
32-
mkdir(path.chars, S_IRWXU | S_IRGRP | S_IROTH);
31+
uint32_t length = (uint32_t)(token - fileName + 1);
32+
pathTail = ffStrCopyN(pathTail, fileName, length);
33+
mkdir(path, S_IRWXU | S_IRGRP | S_IROTH);
3334
fileName = token + 1;
3435
}
3536
}

src/common/io/io_windows.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,14 @@
88

99
static void createSubfolders(const char* fileName)
1010
{
11-
FF_STRBUF_AUTO_DESTROY path = ffStrbufCreate();
11+
char path[MAX_PATH];
1212
char *token = NULL;
13+
char *pathTail = path;
1314
while((token = strchr(fileName, '/')) != NULL)
1415
{
15-
ffStrbufAppendNS(&path, (uint32_t)(token - fileName + 1), fileName);
16-
CreateDirectoryA(path.chars, NULL);
16+
uint32_t length = (uint32_t)(token - fileName + 1);
17+
pathTail = ffStrCopyN(pathTail, fileName, length);
18+
CreateDirectoryA(path, NULL);
1719
fileName = token + 1;
1820
}
1921
}

0 commit comments

Comments
 (0)