r264519 - Check if a path is already absolute before trying to make it so.

Bob Wilson via cfe-commits cfe-commits at lists.llvm.org
Sat Mar 26 11:55:13 PDT 2016


Author: bwilson
Date: Sat Mar 26 13:55:13 2016
New Revision: 264519

URL: http://llvm.org/viewvc/llvm-project?rev=264519&view=rev
Log:
Check if a path is already absolute before trying to make it so.

The FileSystem::makeAbsolute function has been calculating the current
working directory unconditionally, even when it is not needed. This calls
down to llvm::sys::fs::current_path, which is relatively expensive
because it stats two directories, regardless of whether those paths are
already in the stat cache. The net effect is that when using the
VFS, every stat during header search turns into three stats. With this
change, we get back to a single stat for absolute directory paths.

Modified:
    cfe/trunk/lib/Basic/VirtualFileSystem.cpp

Modified: cfe/trunk/lib/Basic/VirtualFileSystem.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Basic/VirtualFileSystem.cpp?rev=264519&r1=264518&r2=264519&view=diff
==============================================================================
--- cfe/trunk/lib/Basic/VirtualFileSystem.cpp (original)
+++ cfe/trunk/lib/Basic/VirtualFileSystem.cpp Sat Mar 26 13:55:13 2016
@@ -100,6 +100,9 @@ FileSystem::getBufferForFile(const llvm:
 }
 
 std::error_code FileSystem::makeAbsolute(SmallVectorImpl<char> &Path) const {
+  if (llvm::sys::path::is_absolute(Path))
+    return std::error_code();
+
   auto WorkingDir = getCurrentWorkingDirectory();
   if (!WorkingDir)
     return WorkingDir.getError();




More information about the cfe-commits mailing list