Skip to content

Commit 74cb287

Browse files
authored
[Support] Windows Filesystem fs::status Conditionally Call GetFileAttributes (#78118)
Rather than conditionally using the output from GetFileAttributesW move the branch to avoid calling GetFileAttributesW entirely if not required. This avoids hitting IO an extra time for a small performance improvement.
1 parent cfa30fa commit 74cb287

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

llvm/lib/Support/Windows/Path.inc

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -777,14 +777,16 @@ std::error_code status(const Twine &path, file_status &result, bool Follow) {
777777
if (std::error_code ec = widenPath(path8, path_utf16))
778778
return ec;
779779

780-
DWORD attr = ::GetFileAttributesW(path_utf16.begin());
781-
if (attr == INVALID_FILE_ATTRIBUTES)
782-
return getStatus(INVALID_HANDLE_VALUE, result);
783-
784780
DWORD Flags = FILE_FLAG_BACKUP_SEMANTICS;
785-
// Handle reparse points.
786-
if (!Follow && (attr & FILE_ATTRIBUTE_REPARSE_POINT))
787-
Flags |= FILE_FLAG_OPEN_REPARSE_POINT;
781+
if (!Follow) {
782+
DWORD attr = ::GetFileAttributesW(path_utf16.begin());
783+
if (attr == INVALID_FILE_ATTRIBUTES)
784+
return getStatus(INVALID_HANDLE_VALUE, result);
785+
786+
// Handle reparse points.
787+
if (attr & FILE_ATTRIBUTE_REPARSE_POINT)
788+
Flags |= FILE_FLAG_OPEN_REPARSE_POINT;
789+
}
788790

789791
ScopedFileHandle h(
790792
::CreateFileW(path_utf16.begin(), 0, // Attributes only.

0 commit comments

Comments
 (0)