[PATCH] D83621: [clang][Tooling] Try to avoid file system access if there is no record for the file in compile_commads.json
Aleksandr Platonov via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Wed Jul 15 06:11:10 PDT 2020
ArcsinX updated this revision to Diff 278161.
ArcsinX added a comment.
Support only directory simlinks.
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D83621/new/
https://reviews.llvm.org/D83621
Files:
clang/lib/Tooling/FileMatchTrie.cpp
clang/unittests/Tooling/CompilationDatabaseTest.cpp
Index: clang/unittests/Tooling/CompilationDatabaseTest.cpp
===================================================================
--- clang/unittests/Tooling/CompilationDatabaseTest.cpp
+++ clang/unittests/Tooling/CompilationDatabaseTest.cpp
@@ -281,6 +281,15 @@
EXPECT_EQ("Cannot resolve relative paths", Error);
}
+TEST_F(FileMatchTrieTest, SingleFile) {
+ Trie.insert("/root/RootFile.cc");
+ EXPECT_EQ("", find("/root/rootfile.cc"));
+ // Add subpath to avoid `if (Children.empty())` special case
+ // which we hit at previous `find()`.
+ Trie.insert("/root/otherpath/OtherFile.cc");
+ EXPECT_EQ("", find("/root/rootfile.cc"));
+}
+
TEST(findCompileArgsInJsonDatabase, FindsNothingIfEmpty) {
std::string ErrorMessage;
CompileCommand NotFound = findCompileArgsInJsonDatabase(
Index: clang/lib/Tooling/FileMatchTrie.cpp
===================================================================
--- clang/lib/Tooling/FileMatchTrie.cpp
+++ clang/lib/Tooling/FileMatchTrie.cpp
@@ -105,8 +105,13 @@
StringRef FileName,
bool &IsAmbiguous,
unsigned ConsumedLength = 0) const {
+ // Note: we support only directory symlinks for performance reasons.
if (Children.empty()) {
- if (Comparator.equivalent(StringRef(Path), FileName))
+ // As far as we do not support file symlinks we compare
+ // basenames here to avoid expensive request to file system.
+ if (llvm::sys::path::filename(Path) ==
+ llvm::sys::path::filename(FileName) &&
+ Comparator.equivalent(StringRef(Path), FileName))
return StringRef(Path);
return {};
}
@@ -121,6 +126,15 @@
if (!Result.empty() || IsAmbiguous)
return Result;
}
+
+ // We failed to find the file with `Children.find()`.
+ // If `ConsumedLength` is equal to 0 then we have tried to find the file
+ // with it's basename. Thus, we do not have files with the same
+ // basename and could return empty result here as far as we
+ // do not support file symlinks.
+ if (ConsumedLength == 0)
+ return {};
+
std::vector<StringRef> AllChildren;
getAll(AllChildren, MatchingChild);
StringRef Result;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D83621.278161.patch
Type: text/x-patch
Size: 2241 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20200715/95dc820c/attachment.bin>
More information about the cfe-commits
mailing list