[PATCH] D51641: [VFS] Cache the current working directory for the real FS.
Eric Liu via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Tue Sep 4 09:21:35 PDT 2018
ioeric created this revision.
ioeric added a reviewer: sammccall.
Herald added a subscriber: cfe-commits.
Repository:
rC Clang
https://reviews.llvm.org/D51641
Files:
lib/Basic/VirtualFileSystem.cpp
Index: lib/Basic/VirtualFileSystem.cpp
===================================================================
--- lib/Basic/VirtualFileSystem.cpp
+++ lib/Basic/VirtualFileSystem.cpp
@@ -243,6 +243,8 @@
std::error_code setCurrentWorkingDirectory(const Twine &Path) override;
std::error_code getRealPath(const Twine &Path,
SmallVectorImpl<char> &Output) const override;
+private:
+ mutable std::string CWDCache;
};
} // namespace
@@ -265,10 +267,13 @@
}
llvm::ErrorOr<std::string> RealFileSystem::getCurrentWorkingDirectory() const {
+ if (!CWDCache.empty())
+ return CWDCache;
SmallString<256> Dir;
if (std::error_code EC = llvm::sys::fs::current_path(Dir))
return EC;
- return Dir.str().str();
+ CWDCache = Dir.str();
+ return CWDCache;
}
std::error_code RealFileSystem::setCurrentWorkingDirectory(const Twine &Path) {
@@ -279,7 +284,14 @@
// difference for example on network filesystems, where symlinks might be
// switched during runtime of the tool. Fixing this depends on having a
// file system abstraction that allows openat() style interactions.
- return llvm::sys::fs::set_current_path(Path);
+ if (auto EC = llvm::sys::fs::set_current_path(Path))
+ return EC;
+
+ CWDCache.clear();
+ auto CWD = getCurrentWorkingDirectory();
+ if (CWD)
+ CWDCache = CWD.get();
+ return CWD.getError();
}
std::error_code
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D51641.163846.patch
Type: text/x-patch
Size: 1403 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20180904/d4e3b844/attachment.bin>
More information about the cfe-commits
mailing list