@@ -804,9 +804,8 @@ namespace {
804
804
// / variables to the `x` variable immediately to its left. A fourth `x` will be
805
805
// / the body case variable, whose parent will be set to the `x` within the final
806
806
// / 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) {
810
809
llvm::SmallDenseMap<Identifier, VarDecl *, 4 > allVars;
811
810
812
811
auto foundVar = [&](VarDecl *VD) {
@@ -833,8 +832,6 @@ static ArrayRef<VarDecl *> getCaseVarDecls(ASTContext &ctx,
833
832
// the last pattern variables we saw.
834
833
for (auto caseVar : caseVars)
835
834
foundVar (caseVar);
836
-
837
- return ctx.AllocateCopy (caseVars);
838
835
}
839
836
840
837
struct FallthroughFinder : ASTWalker {
@@ -885,7 +882,8 @@ CaseStmt::createParsedSwitchCase(ASTContext &ctx, SourceLoc introducerLoc,
885
882
ArrayRef<CaseLabelItem> caseLabelItems,
886
883
SourceLoc unknownAttrLoc, SourceLoc colonLoc,
887
884
BraceStmt *body) {
888
- auto caseVarDecls = getCaseVarDecls (ctx, caseLabelItems);
885
+ SmallVector<VarDecl *, 4 > caseVarDecls;
886
+ getCaseVarDecls (ctx, caseLabelItems, caseVarDecls);
889
887
auto fallthroughStmt = FallthroughFinder ().findFallthrough (body);
890
888
return create (ctx, CaseParentKind::Switch, introducerLoc, caseLabelItems,
891
889
unknownAttrLoc, colonLoc, body, caseVarDecls,
@@ -895,7 +893,8 @@ CaseStmt::createParsedSwitchCase(ASTContext &ctx, SourceLoc introducerLoc,
895
893
CaseStmt *CaseStmt::createParsedDoCatch (ASTContext &ctx, SourceLoc catchLoc,
896
894
ArrayRef<CaseLabelItem> caseLabelItems,
897
895
BraceStmt *body) {
898
- auto caseVarDecls = getCaseVarDecls (ctx, caseLabelItems);
896
+ SmallVector<VarDecl *, 4 > caseVarDecls;
897
+ getCaseVarDecls (ctx, caseLabelItems, caseVarDecls);
899
898
return create (ctx, CaseParentKind::DoCatch, catchLoc, caseLabelItems,
900
899
/* unknownAttrLoc=*/ SourceLoc (), body->getStartLoc (), body,
901
900
caseVarDecls, /* implicit=*/ false , /* fallthroughStmt=*/ nullptr );
@@ -906,7 +905,8 @@ CaseStmt::createImplicit(ASTContext &ctx, CaseParentKind parentKind,
906
905
ArrayRef<CaseLabelItem> caseLabelItems,
907
906
BraceStmt *body,
908
907
NullablePtr<FallthroughStmt> fallthroughStmt) {
909
- auto caseVarDecls = getCaseVarDecls (ctx, caseLabelItems);
908
+ SmallVector<VarDecl *, 4 > caseVarDecls;
909
+ getCaseVarDecls (ctx, caseLabelItems, caseVarDecls);
910
910
return create (ctx, parentKind, /* catchLoc*/ SourceLoc (), caseLabelItems,
911
911
/* unknownAttrLoc*/ SourceLoc (), /* colonLoc*/ SourceLoc (), body,
912
912
caseVarDecls, /* implicit*/ true , fallthroughStmt);
0 commit comments