Skip to content

Commit 126ad5c

Browse files
committed
[Macros] Optimize 'rangeContainsTokenLocWithGeneratedSource'
* Early return for the direct 'true' case. * Instead of comparing the buffer IDs, check f the entire buffer contains the target range. This keeps 'LocCache.lastBufferID' and improves the hit rate.
1 parent 55d4a56 commit 126ad5c

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)