[clangd] Stop isSpelledInSource from printing source locations.

It shows up on profiles, albeit only at 0.1% or so.
This commit is contained in:
Sam McCall 2022-10-05 15:48:28 +02:00
parent e18736149c
commit 0a50eafd1d
1 changed files with 10 additions and 6 deletions

View File

@ -228,12 +228,16 @@ Position sourceLocToPosition(const SourceManager &SM, SourceLocation Loc) {
}
bool isSpelledInSource(SourceLocation Loc, const SourceManager &SM) {
if (Loc.isMacroID()) {
std::string PrintLoc = SM.getSpellingLoc(Loc).printToString(SM);
if (llvm::StringRef(PrintLoc).startswith("<scratch") ||
llvm::StringRef(PrintLoc).startswith("<command line>"))
return false;
}
if (Loc.isFileID())
return true;
auto Spelling = SM.getDecomposedSpellingLoc(Loc);
StringRef SpellingFile = SM.getSLocEntry(Spelling.first).getFile().getName();
if (SpellingFile == "<scratch space>")
return false;
if (SpellingFile == "<built-in>")
// __STDC__ etc are considered spelled, but BAR in arg -DFOO=BAR is not.
return !SM.isWrittenInCommandLineFile(
SM.getComposedLoc(Spelling.first, Spelling.second));
return true;
}