From: Haojian Wu Date: Thu, 8 Mar 2018 16:28:12 +0000 (+0000) Subject: [clangd] Early return for #include goto definition. X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=c6a64d92398c900747667d31305dbddf78296ad3;p=platform%2Fupstream%2Fllvm.git [clangd] Early return for #include goto definition. Summary: This would save cost of walking over the AST, NFC. Reviewers: ilya-biryukov Subscribers: klimek, jkorous-apple, cfe-commits, ioeric Differential Revision: https://reviews.llvm.org/D44251 llvm-svn: 327023 --- diff --git a/clang-tools-extra/clangd/XRefs.cpp b/clang-tools-extra/clangd/XRefs.cpp index 6cc27ec..0744a4f 100644 --- a/clang-tools-extra/clangd/XRefs.cpp +++ b/clang-tools-extra/clangd/XRefs.cpp @@ -174,6 +174,18 @@ std::vector findDefinitions(ParsedAST &AST, Position Pos) { SourceLocation SourceLocationBeg = getBeginningOfIdentifier(AST, Pos, FE); + std::vector Result; + // Handle goto definition for #include. + for (auto &IncludeLoc : AST.getInclusionLocations()) { + Range R = IncludeLoc.first; + Position Pos = sourceLocToPosition(SourceMgr, SourceLocationBeg); + + if (R.contains(Pos)) + Result.push_back(Location{URIForFile{IncludeLoc.second}, {}}); + } + if (!Result.empty()) + return Result; + auto DeclMacrosFinder = std::make_shared( llvm::errs(), SourceLocationBeg, AST.getASTContext(), AST.getPreprocessor()); @@ -187,7 +199,6 @@ std::vector findDefinitions(ParsedAST &AST, Position Pos) { std::vector Decls = DeclMacrosFinder->takeDecls(); std::vector MacroInfos = DeclMacrosFinder->takeMacroInfos(); - std::vector Result; for (auto Item : Decls) { auto L = getDeclarationLocation(AST, Item->getSourceRange()); @@ -203,15 +214,6 @@ std::vector findDefinitions(ParsedAST &AST, Position Pos) { Result.push_back(*L); } - /// Process targets for paths inside #include directive. - for (auto &IncludeLoc : AST.getInclusionLocations()) { - Range R = IncludeLoc.first; - Position Pos = sourceLocToPosition(SourceMgr, SourceLocationBeg); - - if (R.contains(Pos)) - Result.push_back(Location{URIForFile{IncludeLoc.second}, {}}); - } - return Result; }