-
Notifications
You must be signed in to change notification settings - Fork 14.3k
Windows Filesystem fs::status Conditionally Call GetFileAttributes #78118
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Thank you for submitting a Pull Request (PR) to the LLVM Project! This PR will be automatically labeled and the relevant teams will be If you wish to, you can add reviewers by using the "Reviewers" section on this page. If this is not working for you, it is probably because you do not have write If you have received no comments on your PR for a week, you can request a review If you have further questions, they may be answered by the LLVM GitHub User Guide. You can also ask questions in a comment on this PR, on the LLVM Discord or on the forums. |
@llvm/pr-subscribers-llvm-support @llvm/pr-subscribers-platform-windows Author: Haydn Trigg (HaydnTrigg) ChangesRather 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. Full diff: https://github.com/llvm/llvm-project/pull/78118.diff 1 Files Affected:
diff --git a/llvm/lib/Support/Windows/Path.inc b/llvm/lib/Support/Windows/Path.inc
index 2bf68b7972e746..6598586545ddd0 100644
--- a/llvm/lib/Support/Windows/Path.inc
+++ b/llvm/lib/Support/Windows/Path.inc
@@ -777,14 +777,15 @@ 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.
|
✅ With the latest revision this PR passed the C/C++ code formatter. |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice! Less calls to GetFileAttribtuesW is always a good thing!
…ributes (llvm#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.
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.