Skip to content

Commit b43609f

Browse files
authored
Merge pull request swiftlang#84204 from hamishknight/alloc-less
2 parents 4468808 + ea42ecf commit b43609f

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

lib/AST/Stmt.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -804,9 +804,8 @@ namespace {
804804
/// variables to the `x` variable immediately to its left. A fourth `x` will be
805805
/// the body case variable, whose parent will be set to the `x` within the final
806806
/// case item.
807-
static ArrayRef<VarDecl *> getCaseVarDecls(ASTContext &ctx,
808-
ArrayRef<CaseLabelItem> labelItems) {
809-
SmallVector<VarDecl *, 4> caseVars;
807+
static void getCaseVarDecls(ASTContext &ctx, ArrayRef<CaseLabelItem> labelItems,
808+
SmallVectorImpl<VarDecl *> &caseVars) {
810809
llvm::SmallDenseMap<Identifier, VarDecl *, 4> allVars;
811810

812811
auto foundVar = [&](VarDecl *VD) {
@@ -833,8 +832,6 @@ static ArrayRef<VarDecl *> getCaseVarDecls(ASTContext &ctx,
833832
// the last pattern variables we saw.
834833
for (auto caseVar : caseVars)
835834
foundVar(caseVar);
836-
837-
return ctx.AllocateCopy(caseVars);
838835
}
839836

840837
struct FallthroughFinder : ASTWalker {
@@ -885,7 +882,8 @@ CaseStmt::createParsedSwitchCase(ASTContext &ctx, SourceLoc introducerLoc,
885882
ArrayRef<CaseLabelItem> caseLabelItems,
886883
SourceLoc unknownAttrLoc, SourceLoc colonLoc,
887884
BraceStmt *body) {
888-
auto caseVarDecls = getCaseVarDecls(ctx, caseLabelItems);
885+
SmallVector<VarDecl *, 4> caseVarDecls;
886+
getCaseVarDecls(ctx, caseLabelItems, caseVarDecls);
889887
auto fallthroughStmt = FallthroughFinder().findFallthrough(body);
890888
return create(ctx, CaseParentKind::Switch, introducerLoc, caseLabelItems,
891889
unknownAttrLoc, colonLoc, body, caseVarDecls,
@@ -895,7 +893,8 @@ CaseStmt::createParsedSwitchCase(ASTContext &ctx, SourceLoc introducerLoc,
895893
CaseStmt *CaseStmt::createParsedDoCatch(ASTContext &ctx, SourceLoc catchLoc,
896894
ArrayRef<CaseLabelItem> caseLabelItems,
897895
BraceStmt *body) {
898-
auto caseVarDecls = getCaseVarDecls(ctx, caseLabelItems);
896+
SmallVector<VarDecl *, 4> caseVarDecls;
897+
getCaseVarDecls(ctx, caseLabelItems, caseVarDecls);
899898
return create(ctx, CaseParentKind::DoCatch, catchLoc, caseLabelItems,
900899
/*unknownAttrLoc=*/SourceLoc(), body->getStartLoc(), body,
901900
caseVarDecls, /*implicit=*/false, /*fallthroughStmt=*/nullptr);
@@ -906,7 +905,8 @@ CaseStmt::createImplicit(ASTContext &ctx, CaseParentKind parentKind,
906905
ArrayRef<CaseLabelItem> caseLabelItems,
907906
BraceStmt *body,
908907
NullablePtr<FallthroughStmt> fallthroughStmt) {
909-
auto caseVarDecls = getCaseVarDecls(ctx, caseLabelItems);
908+
SmallVector<VarDecl *, 4> caseVarDecls;
909+
getCaseVarDecls(ctx, caseLabelItems, caseVarDecls);
910910
return create(ctx, parentKind, /*catchLoc*/ SourceLoc(), caseLabelItems,
911911
/*unknownAttrLoc*/ SourceLoc(), /*colonLoc*/ SourceLoc(), body,
912912
caseVarDecls, /*implicit*/ true, fallthroughStmt);

0 commit comments

Comments
 (0)