Skip to content
This repository has been archived by the owner on Jan 20, 2024. It is now read-only.

Commit

Permalink
[Support] Windows Filesystem fs::status Conditionally Call GetFileAtt…
Browse files Browse the repository at this point in the history
…ributes (#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.
  • Loading branch information
HaydnTrigg committed Jan 15, 2024
1 parent cfa30fa commit 74cb287
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions llvm/lib/Support/Windows/Path.inc
Original file line number Diff line number Diff line change
Expand Up @@ -777,14 +777,16 @@ std::error_code status(const Twine &path, file_status &result, bool Follow) {
if (std::error_code ec = widenPath(path8, path_utf16))
return ec;

DWORD attr = ::GetFileAttributesW(path_utf16.begin());
if (attr == INVALID_FILE_ATTRIBUTES)
return getStatus(INVALID_HANDLE_VALUE, result);

DWORD Flags = FILE_FLAG_BACKUP_SEMANTICS;
// Handle reparse points.
if (!Follow && (attr & FILE_ATTRIBUTE_REPARSE_POINT))
Flags |= FILE_FLAG_OPEN_REPARSE_POINT;
if (!Follow) {
DWORD attr = ::GetFileAttributesW(path_utf16.begin());
if (attr == INVALID_FILE_ATTRIBUTES)
return getStatus(INVALID_HANDLE_VALUE, result);

// Handle reparse points.
if (attr & FILE_ATTRIBUTE_REPARSE_POINT)
Flags |= FILE_FLAG_OPEN_REPARSE_POINT;
}

ScopedFileHandle h(
::CreateFileW(path_utf16.begin(), 0, // Attributes only.
Expand Down

0 comments on commit 74cb287

Please sign in to comment.