Skip to content

Commit 3ab5a73

Browse files
authored
Merge pull request #20594 from xedin/minor-gsb-cleanups
[GSB] NFC: Couple of minor cleanups
2 parents da724b3 + a21990f commit 3ab5a73

File tree

1 file changed

+14
-24
lines changed

1 file changed

+14
-24
lines changed

lib/AST/GenericSignatureBuilder.cpp

Lines changed: 14 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -3543,11 +3543,11 @@ GenericSignatureBuilder::Implementation::getRewriteTreeRootIfPresent(
35433543
RewriteTreeNode *
35443544
GenericSignatureBuilder::Implementation::getOrCreateRewriteTreeRoot(
35453545
CanType anchor) {
3546-
auto known = RewriteTreeRoots.find(anchor);
3547-
if (known != RewriteTreeRoots.end()) return known->second.get();
3546+
if (auto *root = getRewriteTreeRootIfPresent(anchor))
3547+
return root;
35483548

35493549
auto &root = RewriteTreeRoots[anchor];
3550-
root = std::unique_ptr<RewriteTreeNode>(new RewriteTreeNode(nullptr));
3550+
root = llvm::make_unique<RewriteTreeNode>(nullptr);
35513551
return root.get();
35523552
}
35533553

@@ -4929,35 +4929,25 @@ GenericSignatureBuilder::addSameTypeRequirementBetweenTypeParameters(
49294929
};
49304930

49314931
// Consider the second equivalence class to be modified.
4932-
if (equivClass2)
4933-
equivClass->modified(*this);
4934-
4935-
// Same-type requirements, delayed requirements.
4932+
// Transfer Same-type requirements and delayed requirements.
49364933
if (equivClass2) {
4937-
Impl->DelayedRequirements.append(equivClass2->delayedRequirements.begin(),
4938-
equivClass2->delayedRequirements.end());
4939-
4934+
// Mark as modified and transfer deplayed requirements to the primary queue.
4935+
equivClass2->modified(*this);
49404936
equivClass->sameTypeConstraints.insert(
49414937
equivClass->sameTypeConstraints.end(),
49424938
equivClass2->sameTypeConstraints.begin(),
49434939
equivClass2->sameTypeConstraints.end());
49444940
}
49454941

49464942
// Combine the rewrite rules.
4947-
if (auto rewriteRoot2 = Impl->getOrCreateRewriteTreeRoot(anchor2)) {
4948-
if (auto rewriteRoot1 = Impl->getOrCreateRewriteTreeRoot(anchor1)) {
4949-
// Merge the second rewrite tree into the first.
4950-
if (rewriteRoot2->mergeInto(rewriteRoot1))
4951-
++Impl->RewriteGeneration;
4952-
Impl->RewriteTreeRoots.erase(anchor2);
4953-
} else {
4954-
// Take the second rewrite tree and make it the first.
4955-
auto root2Entry = Impl->RewriteTreeRoots.find(anchor2);
4956-
auto root2Ptr = std::move(root2Entry->second);
4957-
Impl->RewriteTreeRoots.erase(root2Entry);
4958-
(void)Impl->RewriteTreeRoots.insert({anchor1, std::move(root2Ptr)});
4959-
}
4960-
}
4943+
auto *rewriteRoot1 = Impl->getOrCreateRewriteTreeRoot(anchor1);
4944+
auto *rewriteRoot2 = Impl->getOrCreateRewriteTreeRoot(anchor2);
4945+
assert(rewriteRoot1 && rewriteRoot2 &&
4946+
"Couldn't create/retrieve rewrite tree root");
4947+
// Merge the second rewrite tree into the first.
4948+
if (rewriteRoot2->mergeInto(rewriteRoot1))
4949+
++Impl->RewriteGeneration;
4950+
Impl->RewriteTreeRoots.erase(anchor2);
49614951

49624952
// Add a rewrite rule to map the anchor of T2 down to the anchor of T1.
49634953
if (addSameTypeRewriteRule(anchor2, anchor1))

0 commit comments

Comments
 (0)