Skip to content

Commit

Permalink
Merge pull request swiftlang#75130 from rintaro/rangecontainsloc-opti…
Browse files Browse the repository at this point in the history
…mize

[Macros] Optimize 'rangeContainsTokenLocWithGeneratedSource'
  • Loading branch information
rintaro committed Jul 10, 2024
2 parents 5bddd98 + 126ad5c commit 98c1629
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions lib/AST/TypeRefinementContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -182,10 +182,13 @@ TypeRefinementContext::createForWhileStmtBody(ASTContext &Ctx, WhileStmt *S,
/// range.
static bool rangeContainsTokenLocWithGeneratedSource(
SourceManager &sourceMgr, SourceRange parentRange, SourceLoc childLoc) {
auto parentBuffer = sourceMgr.findBufferContainingLoc(parentRange.Start);
if (sourceMgr.rangeContainsTokenLoc(parentRange, childLoc))
return true;

auto childBuffer = sourceMgr.findBufferContainingLoc(childLoc);
while (parentBuffer != childBuffer) {
auto info = sourceMgr.getGeneratedSourceInfo(childBuffer);
while (!sourceMgr.rangeContainsTokenLoc(
sourceMgr.getRangeForBuffer(childBuffer), parentRange.Start)) {
auto *info = sourceMgr.getGeneratedSourceInfo(childBuffer);
if (!info)
return false;

Expand Down

0 comments on commit 98c1629

Please sign in to comment.