Skip to content

Commit 98c1629

Browse files
authored
Merge pull request #75130 from rintaro/rangecontainsloc-optimize
[Macros] Optimize 'rangeContainsTokenLocWithGeneratedSource'
2 parents 5bddd98 + 126ad5c commit 98c1629

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

lib/AST/TypeRefinementContext.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -182,10 +182,13 @@ TypeRefinementContext::createForWhileStmtBody(ASTContext &Ctx, WhileStmt *S,
182182
/// range.
183183
static bool rangeContainsTokenLocWithGeneratedSource(
184184
SourceManager &sourceMgr, SourceRange parentRange, SourceLoc childLoc) {
185-
auto parentBuffer = sourceMgr.findBufferContainingLoc(parentRange.Start);
185+
if (sourceMgr.rangeContainsTokenLoc(parentRange, childLoc))
186+
return true;
187+
186188
auto childBuffer = sourceMgr.findBufferContainingLoc(childLoc);
187-
while (parentBuffer != childBuffer) {
188-
auto info = sourceMgr.getGeneratedSourceInfo(childBuffer);
189+
while (!sourceMgr.rangeContainsTokenLoc(
190+
sourceMgr.getRangeForBuffer(childBuffer), parentRange.Start)) {
191+
auto *info = sourceMgr.getGeneratedSourceInfo(childBuffer);
189192
if (!info)
190193
return false;
191194

0 commit comments

Comments
 (0)