[llvm] 9e0398d - [llvm][vfs] NFC: Promote `lookupInMemoryNode()` to member function
Jan Svoboda via llvm-commits
llvm-commits at lists.llvm.org
Tue Jun 21 07:30:04 PDT 2022
Author: Jan Svoboda
Date: 2022-06-21T16:29:53+02:00
New Revision: 9e0398da8d00b6218aa16a2d602acc765105ed40
URL: https://github.com/llvm/llvm-project/commit/9e0398da8d00b6218aa16a2d602acc765105ed40
DIFF: https://github.com/llvm/llvm-project/commit/9e0398da8d00b6218aa16a2d602acc765105ed40.diff
LOG: [llvm][vfs] NFC: Promote `lookupInMemoryNode()` to member function
Added:
Modified:
llvm/include/llvm/Support/VirtualFileSystem.h
llvm/lib/Support/VirtualFileSystem.cpp
Removed:
################################################################################
diff --git a/llvm/include/llvm/Support/VirtualFileSystem.h b/llvm/include/llvm/Support/VirtualFileSystem.h
index 590e5e95a35f..d1f5dbf6465f 100644
--- a/llvm/include/llvm/Support/VirtualFileSystem.h
+++ b/llvm/include/llvm/Support/VirtualFileSystem.h
@@ -496,6 +496,8 @@ class InMemoryFileSystem : public FileSystem {
Optional<llvm::sys::fs::file_type> Type,
Optional<llvm::sys::fs::perms> Perms, MakeNodeFn MakeNode);
+ ErrorOr<const detail::InMemoryNode *> lookupNode(const Twine &P) const;
+
public:
explicit InMemoryFileSystem(bool UseNormalizedPaths = true);
~InMemoryFileSystem() override;
diff --git a/llvm/lib/Support/VirtualFileSystem.cpp b/llvm/lib/Support/VirtualFileSystem.cpp
index 526792281aa7..9dc77b953ddf 100644
--- a/llvm/lib/Support/VirtualFileSystem.cpp
+++ b/llvm/lib/Support/VirtualFileSystem.cpp
@@ -710,7 +710,7 @@ class InMemoryDirectory : public InMemoryNode {
UniqueID getUniqueID() const { return Stat.getUniqueID(); }
- InMemoryNode *getChild(StringRef Name) {
+ InMemoryNode *getChild(StringRef Name) const {
auto I = Entries.find(Name);
if (I != Entries.end())
return I->second.get();
@@ -897,20 +897,20 @@ bool InMemoryFileSystem::addFileNoOwn(const Twine &P, time_t ModificationTime,
});
}
-static ErrorOr<const detail::InMemoryNode *>
-lookupInMemoryNode(const InMemoryFileSystem &FS, detail::InMemoryDirectory *Dir,
- const Twine &P) {
+ErrorOr<const detail::InMemoryNode *>
+InMemoryFileSystem::lookupNode(const Twine &P) const {
SmallString<128> Path;
P.toVector(Path);
// Fix up relative paths. This just prepends the current working directory.
- std::error_code EC = FS.makeAbsolute(Path);
+ std::error_code EC = makeAbsolute(Path);
assert(!EC);
(void)EC;
- if (FS.useNormalizedPaths())
+ if (useNormalizedPaths())
llvm::sys::path::remove_dots(Path, /*remove_dot_dot=*/true);
+ const detail::InMemoryDirectory *Dir = Root.get();
if (Path.empty())
return Dir;
@@ -943,8 +943,8 @@ lookupInMemoryNode(const InMemoryFileSystem &FS, detail::InMemoryDirectory *Dir,
bool InMemoryFileSystem::addHardLink(const Twine &NewLink,
const Twine &Target) {
- auto NewLinkNode = lookupInMemoryNode(*this, Root.get(), NewLink);
- auto TargetNode = lookupInMemoryNode(*this, Root.get(), Target);
+ auto NewLinkNode = lookupNode(NewLink);
+ auto TargetNode = lookupNode(Target);
// FromPath must not have been added before. ToPath must have been added
// before. Resolved ToPath must be a File.
if (!TargetNode || NewLinkNode || !isa<detail::InMemoryFile>(*TargetNode))
@@ -958,7 +958,7 @@ bool InMemoryFileSystem::addHardLink(const Twine &NewLink,
}
llvm::ErrorOr<Status> InMemoryFileSystem::status(const Twine &Path) {
- auto Node = lookupInMemoryNode(*this, Root.get(), Path);
+ auto Node = lookupNode(Path);
if (Node)
return (*Node)->getStatus(Path);
return Node.getError();
@@ -966,7 +966,7 @@ llvm::ErrorOr<Status> InMemoryFileSystem::status(const Twine &Path) {
llvm::ErrorOr<std::unique_ptr<File>>
InMemoryFileSystem::openFileForRead(const Twine &Path) {
- auto Node = lookupInMemoryNode(*this, Root.get(), Path);
+ auto Node = lookupNode(Path);
if (!Node)
return Node.getError();
@@ -1031,7 +1031,7 @@ class InMemoryDirIterator : public llvm::vfs::detail::DirIterImpl {
directory_iterator InMemoryFileSystem::dir_begin(const Twine &Dir,
std::error_code &EC) {
- auto Node = lookupInMemoryNode(*this, Root.get(), Dir);
+ auto Node = lookupNode(Dir);
if (!Node) {
EC = Node.getError();
return directory_iterator(std::make_shared<InMemoryDirIterator>());
More information about the llvm-commits
mailing list