https://github.com/SergejSalnikov created https://github.com/llvm/llvm-project/pull/164269
Optimize implementations of `getSpellingLocSlowCase` and `getFileLocSlowCase` by inlining methods to avoid repeated calls to `getSLocEntry` and `getFileIDSlow`. >From f27f647b0b43a68c2f4f1773908b200164f5d6ce Mon Sep 17 00:00:00 2001 From: SKill <[email protected]> Date: Mon, 20 Oct 2025 17:17:47 +0200 Subject: [PATCH] Optimize getSpellingLocSlowCase and getFileLocSlowCase Optimize implementations of `getSpellingLocSlowCase` and `getFileLocSlowCase` by inlining methods to avoid repeated calls to `getSLocEntry` --- clang/lib/Basic/SourceManager.cpp | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/clang/lib/Basic/SourceManager.cpp b/clang/lib/Basic/SourceManager.cpp index d8ec837f0f7b9..cedbd31dcef72 100644 --- a/clang/lib/Basic/SourceManager.cpp +++ b/clang/lib/Basic/SourceManager.cpp @@ -908,19 +908,23 @@ getExpansionLocSlowCase(SourceLocation Loc) const { SourceLocation SourceManager::getSpellingLocSlowCase(SourceLocation Loc) const { do { - FileIDAndOffset LocInfo = getDecomposedLoc(Loc); - Loc = getSLocEntry(LocInfo.first).getExpansion().getSpellingLoc(); - Loc = Loc.getLocWithOffset(LocInfo.second); + const SLocEntry &Entry = getSLocEntry(getFileID(Loc)); + Loc = Entry.getExpansion().getSpellingLoc().getLocWithOffset( + Loc.getOffset() - Entry.getOffset()); } while (!Loc.isFileID()); return Loc; } SourceLocation SourceManager::getFileLocSlowCase(SourceLocation Loc) const { do { - if (isMacroArgExpansion(Loc)) - Loc = getImmediateSpellingLoc(Loc); - else - Loc = getImmediateExpansionRange(Loc).getBegin(); + const SLocEntry &Entry = getSLocEntry(getFileID(Loc)); + const ExpansionInfo &ExpInfo = Entry.getExpansion(); + if (ExpInfo.isMacroArgExpansion()) { + Loc = ExpInfo.getSpellingLoc().getLocWithOffset(Loc.getOffset() - + Entry.getOffset()); + } else { + Loc = ExpInfo.getExpansionLocStart(); + } } while (!Loc.isFileID()); return Loc; } _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
