Skip to content

Commit e05fdfd

Browse files
Do not call join() in each iteration.
1 parent 1b05589 commit e05fdfd

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

PC/getpathp.c

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -286,14 +286,20 @@ is_stdlibdir(wchar_t *stdlibdir)
286286
static int
287287
search_for_prefix(wchar_t *prefix, const wchar_t *argv0_path)
288288
{
289-
wchar_t stdlibdir[MAXPATHLEN+1];
290289
/* Search from argv0_path, until LANDMARK is found.
291290
We guarantee 'prefix' is null terminated in bounds. */
292291
wcscpy_s(prefix, MAXPATHLEN+1, argv0_path);
292+
wchar_t stdlibdir[MAXPATHLEN+1];
293+
memset(stdlibdir, 0, sizeof(stdlibdir));
294+
wcscpy_s(stdlibdir, Py_ARRAY_LENGTH(stdlibdir), prefix);
295+
/* We initialize with the longest possible path, in case it doesn't fit.
296+
This also gives us an initial SEP at stdlibdir[wcslen(prefix)]. */
297+
join(stdlibdir, L"lib");
293298
do {
294-
memset(stdlibdir, 0, sizeof(stdlibdir));
295-
wcscpy_s(stdlibdir, Py_ARRAY_LENGTH(stdlibdir), prefix);
296-
join(stdlibdir, L"lib");
299+
assert(stdlibdir[wcslen(prefix)] == SEP);
300+
/* Due to reduce() and our initial value, this result
301+
is guaranteed to fit. */
302+
wcscpy(&stdlibdir[wcslen(prefix) + 1], L"lib");
297303
if (is_stdlibdir(stdlibdir)) {
298304
return 1;
299305
}

0 commit comments

Comments
 (0)