Skip to content

Commit b72fcb2

Browse files
committed
Lift loop out of if block
1 parent 627e049 commit b72fcb2

File tree

1 file changed

+26
-25
lines changed

1 file changed

+26
-25
lines changed

parser/prism/Translator.cc

Lines changed: 26 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1646,12 +1646,6 @@ unique_ptr<parser::Node> Translator::translate(pm_node_t *node) {
16461646
// We can skip the `hasFwdRestArg`/`hasSplat` logic below if it's false.
16471647
// However, we still need the loop if it's true, to be able to tell the two cases apart.
16481648

1649-
NodeVec args;
1650-
// true if the call contains a forwarded argument like `foo(...)`
1651-
auto hasFwdArgs = callNode->arguments != nullptr &&
1652-
PM_NODE_FLAG_P(callNode->arguments, PM_ARGUMENTS_NODE_FLAGS_CONTAINS_FORWARDING);
1653-
auto hasFwdRestArg = false; // true if the call contains an anonymous forwarded rest arg like `foo(*)`
1654-
auto hasSplat = false; // true if the call contains a splatted expression like `foo(*a)`
16551649
pm_keyword_hash_node *kwargsHash = nullptr;
16561650
if (!prismArgs.empty()) {
16571651
// Pop the Kwargs Hash off the end of the arguments, if there is one.
@@ -1686,31 +1680,38 @@ unique_ptr<parser::Node> Translator::translate(pm_node_t *node) {
16861680
prismArgs.remove_suffix(1);
16871681
}
16881682
}
1683+
}
16891684

1690-
// TODO: reserve size for kwargs Hash keys and values, if needed.
1691-
// TODO: reserve size for block, if needed.
1692-
args.reserve(prismArgs.size());
1693-
1694-
for (auto &arg : prismArgs) {
1695-
switch (PM_NODE_TYPE(arg)) {
1696-
case PM_SPLAT_NODE: {
1697-
auto splatNode = down_cast<pm_splat_node>(arg);
1698-
if (splatNode->expression == nullptr) { // An anonymous splat like `f(*)`
1699-
hasFwdRestArg = true;
1700-
} else { // Splatting an expression like `f(*a)`
1701-
hasSplat = true;
1702-
}
1703-
1704-
args.emplace_back(translate(arg));
1685+
// true if the call contains a forwarded argument like `foo(...)`
1686+
auto hasFwdArgs = callNode->arguments != nullptr &&
1687+
PM_NODE_FLAG_P(callNode->arguments, PM_ARGUMENTS_NODE_FLAGS_CONTAINS_FORWARDING);
1688+
auto hasFwdRestArg = false; // true if the call contains an anonymous forwarded rest arg like `foo(*)`
1689+
auto hasSplat = false; // true if the call contains a splatted expression like `foo(*a)`
17051690

1706-
break;
1691+
NodeVec args;
1692+
// TODO: reserve size for kwargs Hash keys and values, if needed.
1693+
// TODO: reserve size for block, if needed.
1694+
args.reserve(prismArgs.size());
1695+
1696+
for (auto &arg : prismArgs) {
1697+
switch (PM_NODE_TYPE(arg)) {
1698+
case PM_SPLAT_NODE: {
1699+
auto splatNode = down_cast<pm_splat_node>(arg);
1700+
if (splatNode->expression == nullptr) { // An anonymous splat like `f(*)`
1701+
hasFwdRestArg = true;
1702+
} else { // Splatting an expression like `f(*a)`
1703+
hasSplat = true;
17071704
}
17081705

1709-
default:
1710-
args.emplace_back(translate(arg));
1706+
args.emplace_back(translate(arg));
17111707

1712-
break;
1708+
break;
17131709
}
1710+
1711+
default:
1712+
args.emplace_back(translate(arg));
1713+
1714+
break;
17141715
}
17151716
}
17161717

0 commit comments

Comments
 (0)