Skip to content

Commit a33eaeb

Browse files
committed
Style tweak and an extra comment.
Change _swift_initRootPath() to do an early return, which reduces indentation. Add a comment to reinforce that we can't use GetFinalPathNameByHandle() in _swift_initRuntimePath(). rdar://103071801
1 parent 5309463 commit a33eaeb

File tree

1 file changed

+18
-13
lines changed

1 file changed

+18
-13
lines changed

stdlib/public/runtime/Paths.cpp

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -244,22 +244,24 @@ _swift_initRootPath(void *)
244244
{
245245
// SWIFT_ROOT overrides the path returned by this function
246246
const char *swiftRoot = swift::runtime::environment::SWIFT_ROOT();
247-
if (swiftRoot && *swiftRoot) {
248-
size_t len = std::strlen(swiftRoot);
249247

250-
// Ensure that there's a trailing slash
251-
if (_swift_isPathSep(swiftRoot[len - 1])) {
252-
rootPath = swiftRoot;
253-
} else {
254-
char *thePath = (char *)malloc(len + 2);
255-
std::memcpy(thePath, swiftRoot, len);
256-
thePath[len] = PATHSEP_CHR;
257-
thePath[len + 1] = 0;
248+
if (!swiftRoot || !*swiftRoot) {
249+
rootPath = _swift_getDefaultRootPath();
250+
return;
251+
}
258252

259-
rootPath = thePath;
260-
}
253+
size_t len = std::strlen(swiftRoot);
254+
255+
// Ensure that there's a trailing slash
256+
if (_swift_isPathSep(swiftRoot[len - 1])) {
257+
rootPath = swiftRoot;
261258
} else {
262-
rootPath = _swift_getDefaultRootPath();
259+
char *thePath = (char *)malloc(len + 2);
260+
std::memcpy(thePath, swiftRoot, len);
261+
thePath[len] = PATHSEP_CHR;
262+
thePath[len + 1] = 0;
263+
264+
rootPath = thePath;
263265
}
264266
}
265267

@@ -479,6 +481,9 @@ _swift_initRuntimePath(void *) {
479481
const DWORD dwBufSize = 4096;
480482
LPWSTR lpFilename = (LPWSTR)std::malloc(dwBufSize * sizeof(WCHAR));
481483

484+
// Again, we can't use GetFinalPathNameByHandle for the reasons given
485+
// above.
486+
482487
DWORD dwRet = GetMappedFileNameW(GetCurrentProcess(),
483488
(void *)_swift_initRuntimePath,
484489
lpFilename,

0 commit comments

Comments
 (0)