aboutsummaryrefslogtreecommitdiff
path: root/clang/unittests/Tooling/CompilationDatabaseTest.cpp
diff options
context:
space:
mode:
authorAleksandr Platonov <platonov.aleksandr@huawei.com>2020-07-17 18:48:56 +0200
committerSam McCall <sam.mccall@gmail.com>2020-07-17 18:49:14 +0200
commitd19f0666bcd8f7d26aaf4019244c3ed91e47b1b7 (patch)
tree2a38bb3178da1083f5a7072639e6262124a6a67e /clang/unittests/Tooling/CompilationDatabaseTest.cpp
parent0e347c0ff0a88a8412299d024c2f32201fe342d1 (diff)
downloadllvm-d19f0666bcd8f7d26aaf4019244c3ed91e47b1b7.zip
llvm-d19f0666bcd8f7d26aaf4019244c3ed91e47b1b7.tar.gz
llvm-d19f0666bcd8f7d26aaf4019244c3ed91e47b1b7.tar.bz2
[clang][Tooling] Try to avoid file system access if there is no record for the file in compile_commads.json
Summary: If there is no record in compile_commands.json, we try to find suitable record with `MatchTrie.findEquivalent()` call. This is very expensive operation with a lot of `llvm::sys::fs::equivalent()` calls in some cases. This patch disables file symlinks for performance reasons. Example scenario without this patch: - compile_commands.json generated at clangd build (contains ~3000 files). - it tooks more than 1 second to get compile command for newly created file in the root folder of LLVM project. - we wait for 1 second every time when clangd requests compile command for this file (at file change). Reviewers: sammccall, kadircet, hokein Reviewed By: sammccall Subscribers: chandlerc, djasper, klimek, ilya-biryukov, kadircet, usaxena95, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D83621
Diffstat (limited to 'clang/unittests/Tooling/CompilationDatabaseTest.cpp')
-rw-r--r--clang/unittests/Tooling/CompilationDatabaseTest.cpp9
1 files changed, 9 insertions, 0 deletions
diff --git a/clang/unittests/Tooling/CompilationDatabaseTest.cpp b/clang/unittests/Tooling/CompilationDatabaseTest.cpp
index cc948b8..3bfb0ec 100644
--- a/clang/unittests/Tooling/CompilationDatabaseTest.cpp
+++ b/clang/unittests/Tooling/CompilationDatabaseTest.cpp
@@ -281,6 +281,15 @@ TEST_F(FileMatchTrieTest, CannotResolveRelativePath) {
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(