[Lldb-commits] [lldb] r315378 - Support: Have directory_iterator::status() return FindFirstFileEx/FindNextFile results on Windows.

Peter Collingbourne via lldb-commits lldb-commits at lists.llvm.org
Tue Oct 10 15:19:46 PDT 2017


Author: pcc
Date: Tue Oct 10 15:19:46 2017
New Revision: 315378

URL: http://llvm.org/viewvc/llvm-project?rev=315378&view=rev
Log:
Support: Have directory_iterator::status() return FindFirstFileEx/FindNextFile results on Windows.

This allows clients to avoid an unnecessary fs::status() call on each
directory entry. Because the information returned by FindFirstFileEx
is a subset of the information returned by a regular status() call,
I needed to extract a base class from file_status that contains only
that information.

On my machine, this reduces the time required to enumerate a ThinLTO
cache directory containing 520k files from almost 4 minutes to less
than 2 seconds.

Differential Revision: https://reviews.llvm.org/D38716

Modified:
    lldb/trunk/source/Commands/CommandCompletions.cpp
    lldb/trunk/source/Utility/FileSpec.cpp

Modified: lldb/trunk/source/Commands/CommandCompletions.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Commands/CommandCompletions.cpp?rev=315378&r1=315377&r2=315378&view=diff
==============================================================================
--- lldb/trunk/source/Commands/CommandCompletions.cpp (original)
+++ lldb/trunk/source/Commands/CommandCompletions.cpp Tue Oct 10 15:19:46 2017
@@ -199,14 +199,14 @@ static int DiskFilesOrDirectories(const
 
     // We have a match.
 
-    fs::file_status st;
-    if ((EC = Entry.status(st)))
+    llvm::ErrorOr<fs::basic_file_status> st = Entry.status();
+    if (!st)
       continue;
 
     // If it's a symlink, then we treat it as a directory as long as the target
     // is a directory.
-    bool is_dir = fs::is_directory(st);
-    if (fs::is_symlink_file(st)) {
+    bool is_dir = fs::is_directory(*st);
+    if (fs::is_symlink_file(*st)) {
       fs::file_status target_st;
       if (!fs::status(Entry.path(), target_st))
         is_dir = fs::is_directory(target_st);

Modified: lldb/trunk/source/Utility/FileSpec.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Utility/FileSpec.cpp?rev=315378&r1=315377&r2=315378&view=diff
==============================================================================
--- lldb/trunk/source/Utility/FileSpec.cpp (original)
+++ lldb/trunk/source/Utility/FileSpec.cpp Tue Oct 10 15:19:46 2017
@@ -700,18 +700,18 @@ void FileSpec::EnumerateDirectory(llvm::
   fs::recursive_directory_iterator End;
   for (; Iter != End && !EC; Iter.increment(EC)) {
     const auto &Item = *Iter;
-    fs::file_status Status;
-    if ((EC = Item.status(Status)))
+    llvm::ErrorOr<fs::basic_file_status> Status = Item.status();
+    if (!Status)
       break;
-    if (!find_files && fs::is_regular_file(Status))
+    if (!find_files && fs::is_regular_file(*Status))
       continue;
-    if (!find_directories && fs::is_directory(Status))
+    if (!find_directories && fs::is_directory(*Status))
       continue;
-    if (!find_other && fs::is_other(Status))
+    if (!find_other && fs::is_other(*Status))
       continue;
 
     FileSpec Spec(Item.path(), false);
-    auto Result = callback(callback_baton, Status.type(), Spec);
+    auto Result = callback(callback_baton, Status->type(), Spec);
     if (Result == eEnumerateDirectoryResultQuit)
       return;
     if (Result == eEnumerateDirectoryResultNext) {




More information about the lldb-commits mailing list