Skip to content

Commit 3e97d72

Browse files
committed
[AST] Turn CaseBodyVariables into an ArrayRef
We don't need to store a `MutableArrayRef`.
1 parent 63286ae commit 3e97d72

File tree

2 files changed

+8
-26
lines changed

2 files changed

+8
-26
lines changed

include/swift/AST/Stmt.h

Lines changed: 4 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1222,12 +1222,12 @@ class CaseStmt final
12221222

12231223
llvm::PointerIntPair<BraceStmt *, 1, bool> BodyAndHasFallthrough;
12241224

1225-
std::optional<MutableArrayRef<VarDecl *>> CaseBodyVariables;
1225+
std::optional<ArrayRef<VarDecl *>> CaseBodyVariables;
12261226

12271227
CaseStmt(CaseParentKind ParentKind, SourceLoc ItemIntroducerLoc,
12281228
ArrayRef<CaseLabelItem> CaseLabelItems, SourceLoc UnknownAttrLoc,
12291229
SourceLoc ItemTerminatorLoc, BraceStmt *Body,
1230-
std::optional<MutableArrayRef<VarDecl *>> CaseBodyVariables,
1230+
std::optional<ArrayRef<VarDecl *>> CaseBodyVariables,
12311231
std::optional<bool> Implicit,
12321232
NullablePtr<FallthroughStmt> fallthroughStmt);
12331233

@@ -1248,7 +1248,7 @@ class CaseStmt final
12481248
create(ASTContext &C, CaseParentKind ParentKind, SourceLoc ItemIntroducerLoc,
12491249
ArrayRef<CaseLabelItem> CaseLabelItems, SourceLoc UnknownAttrLoc,
12501250
SourceLoc ItemTerminatorLoc, BraceStmt *Body,
1251-
std::optional<MutableArrayRef<VarDecl *>> CaseBodyVariables,
1251+
std::optional<ArrayRef<VarDecl *>> CaseBodyVariables,
12521252
std::optional<bool> Implicit = std::nullopt,
12531253
NullablePtr<FallthroughStmt> fallthroughStmt = nullptr);
12541254

@@ -1350,32 +1350,14 @@ class CaseStmt final
13501350
/// where one wants a non-asserting version, \see
13511351
/// getCaseBodyVariablesOrEmptyArray.
13521352
ArrayRef<VarDecl *> getCaseBodyVariables() const {
1353-
ArrayRef<VarDecl *> a = *CaseBodyVariables;
1354-
return a;
1353+
return *CaseBodyVariables;
13551354
}
13561355

13571356
bool hasCaseBodyVariables() const { return CaseBodyVariables.has_value(); }
13581357

1359-
/// Return an MutableArrayRef containing the case body variables of this
1360-
/// CaseStmt.
1361-
///
1362-
/// Asserts if case body variables was not explicitly initialized. In contexts
1363-
/// where one wants a non-asserting version, \see
1364-
/// getCaseBodyVariablesOrEmptyArray.
1365-
MutableArrayRef<VarDecl *> getCaseBodyVariables() {
1366-
return *CaseBodyVariables;
1367-
}
1368-
13691358
ArrayRef<VarDecl *> getCaseBodyVariablesOrEmptyArray() const {
13701359
if (!CaseBodyVariables)
13711360
return ArrayRef<VarDecl *>();
1372-
ArrayRef<VarDecl *> a = *CaseBodyVariables;
1373-
return a;
1374-
}
1375-
1376-
MutableArrayRef<VarDecl *> getCaseBodyVariablesOrEmptyArray() {
1377-
if (!CaseBodyVariables)
1378-
return MutableArrayRef<VarDecl *>();
13791361
return *CaseBodyVariables;
13801362
}
13811363

lib/AST/Stmt.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -753,7 +753,7 @@ CaseStmt::CaseStmt(CaseParentKind parentKind, SourceLoc itemIntroducerLoc,
753753
ArrayRef<CaseLabelItem> caseLabelItems,
754754
SourceLoc unknownAttrLoc, SourceLoc itemTerminatorLoc,
755755
BraceStmt *body,
756-
std::optional<MutableArrayRef<VarDecl *>> caseBodyVariables,
756+
std::optional<ArrayRef<VarDecl *>> caseBodyVariables,
757757
std::optional<bool> implicit,
758758
NullablePtr<FallthroughStmt> fallthroughStmt)
759759
: Stmt(StmtKind::Case, getDefaultImplicitFlag(implicit, itemIntroducerLoc)),
@@ -781,13 +781,13 @@ CaseStmt::CaseStmt(CaseParentKind parentKind, SourceLoc itemIntroducerLoc,
781781
new (&items[i]) CaseLabelItem(caseLabelItems[i]);
782782
items[i].getPattern()->markOwnedByStatement(this);
783783
}
784-
for (auto *vd : caseBodyVariables.value_or(MutableArrayRef<VarDecl *>())) {
784+
for (auto *vd : getCaseBodyVariablesOrEmptyArray()) {
785785
vd->setParentPatternStmt(this);
786786
}
787787
}
788788

789789
namespace {
790-
static MutableArrayRef<VarDecl *>
790+
static ArrayRef<VarDecl *>
791791
getCaseVarDecls(ASTContext &ctx, ArrayRef<CaseLabelItem> labelItems) {
792792
// Grab the first case label item pattern and use it to initialize the case
793793
// body var decls.
@@ -871,7 +871,7 @@ CaseStmt *
871871
CaseStmt::create(ASTContext &ctx, CaseParentKind ParentKind, SourceLoc caseLoc,
872872
ArrayRef<CaseLabelItem> caseLabelItems,
873873
SourceLoc unknownAttrLoc, SourceLoc colonLoc, BraceStmt *body,
874-
std::optional<MutableArrayRef<VarDecl *>> caseVarDecls,
874+
std::optional<ArrayRef<VarDecl *>> caseVarDecls,
875875
std::optional<bool> implicit,
876876
NullablePtr<FallthroughStmt> fallthroughStmt) {
877877
void *mem =

0 commit comments

Comments
 (0)