Skip to content

Commit 0146338

Browse files
committed
Minor clean-up of favorCallOverloads().
Small code shuffling to put related code together and a break from the main loop earlier. NFC.
1 parent 998dad8 commit 0146338

File tree

1 file changed

+16
-24
lines changed

1 file changed

+16
-24
lines changed

lib/Sema/CSGen.cpp

Lines changed: 16 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -661,47 +661,39 @@ namespace {
661661
}
662662
}
663663

664-
SmallVector<Constraint *, 4> favoredConstraints;
665-
666-
TypeBase *favoredTy = nullptr;
667-
668-
// Copy over the existing bindings, dividing the constraints up
669-
// into "favored" and non-favored lists.
670-
for (auto oldConstraint : oldConstraints) {
671-
auto overloadChoice = oldConstraint->getOverloadChoice();
672-
if (isFavored(overloadChoice.getDecl())) {
673-
favoredConstraints.push_back(oldConstraint);
674-
675-
favoredTy = overloadChoice.getDecl()->
676-
getType()->getAs<AnyFunctionType>()->
677-
getResult().getPointer();
678-
}
679-
}
680-
681-
if (favoredConstraints.size() == 1) {
682-
CS.setFavoredType(expr, favoredTy);
683-
}
684-
685664
// If there might be replacement constraints, get them now.
686665
SmallVector<Constraint *, 4> replacementConstraints;
687666
if (createReplacements)
688667
createReplacements(tyvarType, oldConstraints, replacementConstraints);
689-
668+
669+
// Copy over the existing bindings, dividing the constraints up
670+
// into "favored" and non-favored lists.
671+
SmallVector<Constraint *, 4> favoredConstraints;
672+
for (auto oldConstraint : oldConstraints)
673+
if (isFavored(oldConstraint->getOverloadChoice().getDecl()))
674+
favoredConstraints.push_back(oldConstraint);
675+
690676
// If we did not find any favored constraints, just introduce
691677
// the replacement constraints (if they differ).
692678
if (favoredConstraints.empty()) {
693679
if (replacementConstraints.size() > oldConstraints.size()) {
694680
// Remove the old constraint.
695681
CS.removeInactiveConstraint(constraint);
696-
697682
CS.addConstraint(
698683
Constraint::createDisjunction(CS,
699684
replacementConstraints,
700685
csLoc));
701686
}
702687
break;
703688
}
704-
689+
690+
if (favoredConstraints.size() == 1) {
691+
auto overloadChoice = favoredConstraints[0]->getOverloadChoice();
692+
auto overloadType = overloadChoice.getDecl()->getType();
693+
auto resultType = overloadType->getAs<AnyFunctionType>()->getResult();
694+
CS.setFavoredType(expr, resultType.getPointer());
695+
}
696+
705697
// Remove the original constraint from the inactive constraint
706698
// list and add the new one.
707699
CS.removeInactiveConstraint(constraint);

0 commit comments

Comments
 (0)