Skip to content

Commit 2e599de

Browse files
Changqing-JINGCopilot
andcommitted
Fix review
Co-authored-by: Copilot <copilot@github.com>
1 parent 061a332 commit 2e599de

1 file changed

Lines changed: 8 additions & 7 deletions

File tree

src/passes/CodeFolding.cpp

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -317,20 +317,22 @@ struct CodeFolding
317317
if (it != exitingBranchCache.end()) {
318318
return !it->second.empty();
319319
}
320-
return populateExitingBranchCache(expr);
320+
return !populateExitingBranchCache(expr).empty();
321321
}
322322

323323
// Walk |root| bottom-up computing exiting branches. Name sets are kept
324324
// transiently (moved from children, erased after merge). Only the root's
325325
// name set is persisted. Already-cached subtrees are skipped via scan(),
326326
// and their cached names are merged in precisely.
327-
bool populateExitingBranchCache(Expression* root) {
327+
// Returns a reference to the root's cached set (which may be empty).
328+
const std::unordered_set<Name>&
329+
populateExitingBranchCache(Expression* root) {
328330
struct CachePopulator
329331
: public PostWalker<CachePopulator,
330332
UnifiedExpressionVisitor<CachePopulator>> {
331333
std::unordered_map<Expression*, std::unordered_set<Name>>& resultCache;
332334
Expression* root;
333-
bool rootResult = false;
335+
const std::unordered_set<Name>* rootResult = nullptr;
334336
std::unordered_map<Expression*, std::unordered_set<Name>> nameSets;
335337

336338
CachePopulator(
@@ -388,17 +390,16 @@ struct CodeFolding
388390
if (curr == root) {
389391
auto it = nameSets.find(curr);
390392
if (it != nameSets.end()) {
391-
resultCache[curr] = std::move(it->second);
392-
rootResult = true;
393+
rootResult = &(resultCache[curr] = std::move(it->second));
393394
} else {
394-
resultCache[curr] = {};
395+
rootResult = &(resultCache[curr] = {});
395396
}
396397
}
397398
}
398399
};
399400
CachePopulator populator(exitingBranchCache, root);
400401
populator.walk(root);
401-
return populator.rootResult;
402+
return *populator.rootResult;
402403
}
403404

404405
// check if we can move a list of items out of another item. we can't do so

0 commit comments

Comments
 (0)