From ea42ecf2bfc3e63ac80939cb9a76cecad405ad51 Mon Sep 17 00:00:00 2001 From: Hamish Knight Date: Wed, 10 Sep 2025 17:04:13 +0100 Subject: [PATCH] [AST] NFC: Remove an unnecessary allocation I missed this when changing the case body vars to be tail allocated, remove the use of `AllocateCopy`. --- lib/AST/Stmt.cpp | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/lib/AST/Stmt.cpp b/lib/AST/Stmt.cpp index 782dffd49e2ce..f1460e2383ed6 100644 --- a/lib/AST/Stmt.cpp +++ b/lib/AST/Stmt.cpp @@ -804,9 +804,8 @@ namespace { /// variables to the `x` variable immediately to its left. A fourth `x` will be /// the body case variable, whose parent will be set to the `x` within the final /// case item. -static ArrayRef getCaseVarDecls(ASTContext &ctx, - ArrayRef labelItems) { - SmallVector caseVars; +static void getCaseVarDecls(ASTContext &ctx, ArrayRef labelItems, + SmallVectorImpl &caseVars) { llvm::SmallDenseMap allVars; auto foundVar = [&](VarDecl *VD) { @@ -833,8 +832,6 @@ static ArrayRef getCaseVarDecls(ASTContext &ctx, // the last pattern variables we saw. for (auto caseVar : caseVars) foundVar(caseVar); - - return ctx.AllocateCopy(caseVars); } struct FallthroughFinder : ASTWalker { @@ -885,7 +882,8 @@ CaseStmt::createParsedSwitchCase(ASTContext &ctx, SourceLoc introducerLoc, ArrayRef caseLabelItems, SourceLoc unknownAttrLoc, SourceLoc colonLoc, BraceStmt *body) { - auto caseVarDecls = getCaseVarDecls(ctx, caseLabelItems); + SmallVector caseVarDecls; + getCaseVarDecls(ctx, caseLabelItems, caseVarDecls); auto fallthroughStmt = FallthroughFinder().findFallthrough(body); return create(ctx, CaseParentKind::Switch, introducerLoc, caseLabelItems, unknownAttrLoc, colonLoc, body, caseVarDecls, @@ -895,7 +893,8 @@ CaseStmt::createParsedSwitchCase(ASTContext &ctx, SourceLoc introducerLoc, CaseStmt *CaseStmt::createParsedDoCatch(ASTContext &ctx, SourceLoc catchLoc, ArrayRef caseLabelItems, BraceStmt *body) { - auto caseVarDecls = getCaseVarDecls(ctx, caseLabelItems); + SmallVector caseVarDecls; + getCaseVarDecls(ctx, caseLabelItems, caseVarDecls); return create(ctx, CaseParentKind::DoCatch, catchLoc, caseLabelItems, /*unknownAttrLoc=*/SourceLoc(), body->getStartLoc(), body, caseVarDecls, /*implicit=*/false, /*fallthroughStmt=*/nullptr); @@ -906,7 +905,8 @@ CaseStmt::createImplicit(ASTContext &ctx, CaseParentKind parentKind, ArrayRef caseLabelItems, BraceStmt *body, NullablePtr fallthroughStmt) { - auto caseVarDecls = getCaseVarDecls(ctx, caseLabelItems); + SmallVector caseVarDecls; + getCaseVarDecls(ctx, caseLabelItems, caseVarDecls); return create(ctx, parentKind, /*catchLoc*/ SourceLoc(), caseLabelItems, /*unknownAttrLoc*/ SourceLoc(), /*colonLoc*/ SourceLoc(), body, caseVarDecls, /*implicit*/ true, fallthroughStmt);