[clang] [clang] Optimize SourceManager.getSpellingLocSlowCase and SourceManager.getFileLocSlowCase (PR #164269)
via cfe-commits
cfe-commits at lists.llvm.org
Sat Oct 25 02:48:40 PDT 2025
================
@@ -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();
+ }
----------------
SergejSalnikov wrote:
I've tested the following 3 PRs together, but I don't know how to interpret the results.
https://github.com/llvm/llvm-project/pull/163982
https://github.com/llvm/llvm-project/pull/164269
https://github.com/llvm/llvm-project/pull/163982
<img width="1514" height="799" alt="image" src="https://github.com/user-attachments/assets/d7583fa2-f1a0-4158-b231-bca2d8f283de" />
https://github.com/llvm/llvm-project/pull/164269
More information about the cfe-commits
mailing list