Author: hokein Date: Thu Mar 8 08:28:12 2018 New Revision: 327023 URL: http://llvm.org/viewvc/llvm-project?rev=327023&view=rev Log: [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 Modified: clang-tools-extra/trunk/clangd/XRefs.cpp Modified: clang-tools-extra/trunk/clangd/XRefs.cpp URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/XRefs.cpp?rev=327023&r1=327022&r2=327023&view=diff ============================================================================== --- clang-tools-extra/trunk/clangd/XRefs.cpp (original) +++ clang-tools-extra/trunk/clangd/XRefs.cpp Thu Mar 8 08:28:12 2018 @@ -174,6 +174,18 @@ std::vector<Location> findDefinitions(Pa SourceLocation SourceLocationBeg = getBeginningOfIdentifier(AST, Pos, FE); + std::vector<Location> 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<DeclarationAndMacrosFinder>( llvm::errs(), SourceLocationBeg, AST.getASTContext(), AST.getPreprocessor()); @@ -187,7 +199,6 @@ std::vector<Location> findDefinitions(Pa std::vector<const Decl *> Decls = DeclMacrosFinder->takeDecls(); std::vector<MacroDecl> MacroInfos = DeclMacrosFinder->takeMacroInfos(); - std::vector<Location> Result; for (auto Item : Decls) { auto L = getDeclarationLocation(AST, Item->getSourceRange()); @@ -203,15 +214,6 @@ std::vector<Location> findDefinitions(Pa 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; } _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits