[PATCH] D38715: Support: On Windows, speculatively call DeleteFileW from sys::fs::remove().

Peter Collingbourne via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Oct 9 21:35:41 PDT 2017


pcc created this revision.
Herald added a subscriber: hiraditya.

This saves a call to stat().


https://reviews.llvm.org/D38715

Files:
  llvm/lib/Support/Windows/Path.inc


Index: llvm/lib/Support/Windows/Path.inc
===================================================================
--- llvm/lib/Support/Windows/Path.inc
+++ llvm/lib/Support/Windows/Path.inc
@@ -259,26 +259,21 @@
 std::error_code remove(const Twine &path, bool IgnoreNonExisting) {
   SmallVector<wchar_t, 128> path_utf16;
 
-  file_status ST;
-  if (std::error_code EC = status(path, ST)) {
-    if (EC != errc::no_such_file_or_directory || !IgnoreNonExisting)
-      return EC;
-    return std::error_code();
-  }
-
   if (std::error_code ec = widenPath(path, path_utf16))
     return ec;
 
-  if (ST.type() == file_type::directory_file) {
-    if (!::RemoveDirectoryW(c_str(path_utf16))) {
-      std::error_code EC = mapWindowsError(::GetLastError());
-      if (EC != errc::no_such_file_or_directory || !IgnoreNonExisting)
-        return EC;
-    }
-    return std::error_code();
-  }
+  // Speculate that the path is actually a file in order to save a stat() call.
   if (!::DeleteFileW(c_str(path_utf16))) {
     std::error_code EC = mapWindowsError(::GetLastError());
+    if (EC == errc::permission_denied) {
+      if (!::RemoveDirectoryW(c_str(path_utf16))) {
+        std::error_code EC = mapWindowsError(::GetLastError());
+        if (EC != errc::no_such_file_or_directory || !IgnoreNonExisting)
+          return EC;
+      }
+      return std::error_code();
+    }
+
     if (EC != errc::no_such_file_or_directory || !IgnoreNonExisting)
       return EC;
   }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D38715.118313.patch
Type: text/x-patch
Size: 1471 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20171010/222460ad/attachment.bin>


More information about the llvm-commits mailing list