]> granicus.if.org Git - clang/commitdiff
Check if a path is already absolute before trying to make it so.
authorBob Wilson <bob.wilson@apple.com>
Sat, 26 Mar 2016 18:55:13 +0000 (18:55 +0000)
committerBob Wilson <bob.wilson@apple.com>
Sat, 26 Mar 2016 18:55:13 +0000 (18:55 +0000)
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.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@264519 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Basic/VirtualFileSystem.cpp

index 83400cfcd7dff3456a89fa75b9880711232d75aa..325e5eb7bb7e48e1f771a922dc73d11b74cef3b8 100644 (file)
@@ -100,6 +100,9 @@ FileSystem::getBufferForFile(const llvm::Twine &Name, int64_t FileSize,
 }
 
 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();