Skip to content

Commit 2010dae

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. (cherry picked from commit 126ad5c)
1 parent c43fa37 commit 2010dae

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
@@ -181,10 +181,13 @@ TypeRefinementContext::createForWhileStmtBody(ASTContext &Ctx, WhileStmt *S,
181181
/// range.
182182
static bool rangeContainsTokenLocWithGeneratedSource(
183183
SourceManager &sourceMgr, SourceRange parentRange, SourceLoc childLoc) {
184-
auto parentBuffer = sourceMgr.findBufferContainingLoc(parentRange.Start);
184+
if (sourceMgr.rangeContainsTokenLoc(parentRange, childLoc))
185+
return true;
186+
185187
auto childBuffer = sourceMgr.findBufferContainingLoc(childLoc);
186-
while (parentBuffer != childBuffer) {
187-
auto info = sourceMgr.getGeneratedSourceInfo(childBuffer);
188+
while (!sourceMgr.rangeContainsTokenLoc(
189+
sourceMgr.getRangeForBuffer(childBuffer), parentRange.Start)) {
190+
auto *info = sourceMgr.getGeneratedSourceInfo(childBuffer);
188191
if (!info)
189192
return false;
190193

0 commit comments

Comments
 (0)