Skip to content

Commit 88e26b4

Browse files
committed
change nextArgIdx to local variable
1 parent 34e895c commit 88e26b4

File tree

1 file changed

+22
-16
lines changed

1 file changed

+22
-16
lines changed

lib/Sema/CSSimplify.cpp

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@ matchCallArguments(SmallVectorImpl<AnyFunctionType::Param> &args,
232232
parameterBindings.resize(numParams);
233233

234234
// Keep track of which arguments we have claimed from the argument tuple.
235-
unsigned nextArgIdx = 0, numArgs = args.size();
235+
unsigned numArgs = args.size();
236236
SmallVector<bool, 4> claimedArgs(numArgs, false);
237237
SmallVector<Identifier, 4> actualArgNames;
238238
unsigned numClaimedArgs = 0;
@@ -278,18 +278,18 @@ matchCallArguments(SmallVectorImpl<AnyFunctionType::Param> &args,
278278
};
279279

280280
// Local function that skips over any claimed arguments.
281-
auto skipClaimedArgs = [&]() {
281+
auto skipClaimedArgs = [&](unsigned &nextArgIdx) {
282282
while (nextArgIdx != numArgs && claimedArgs[nextArgIdx])
283283
++nextArgIdx;
284284
};
285285

286286
// Local function that retrieves the next unclaimed argument with the given
287287
// name (which may be empty). This routine claims the argument.
288-
auto claimNextNamed
289-
= [&](Identifier paramLabel, bool ignoreNameMismatch,
290-
bool forVariadic = false) -> Optional<unsigned> {
288+
auto claimNextNamed = [&](unsigned &nextArgIdx, Identifier paramLabel,
289+
bool ignoreNameMismatch,
290+
bool forVariadic = false) -> Optional<unsigned> {
291291
// Skip over any claimed arguments.
292-
skipClaimedArgs();
292+
skipClaimedArgs(nextArgIdx);
293293

294294
// If we've claimed all of the arguments, there's nothing more to do.
295295
if (numClaimedArgs == numArgs)
@@ -380,13 +380,14 @@ matchCallArguments(SmallVectorImpl<AnyFunctionType::Param> &args,
380380
// Local function that attempts to bind the given parameter to arguments in
381381
// the list.
382382
bool haveUnfulfilledParams = false;
383-
auto bindNextParameter = [&](bool ignoreNameMismatch) {
383+
auto bindNextParameter = [&](unsigned &nextArgIdx, bool ignoreNameMismatch) {
384384
const auto &param = params[paramIdx];
385385

386386
// Handle variadic parameters.
387387
if (param.isVariadic()) {
388388
// Claim the next argument with the name of this parameter.
389-
auto claimed = claimNextNamed(param.getLabel(), ignoreNameMismatch);
389+
auto claimed =
390+
claimNextNamed(nextArgIdx, param.getLabel(), ignoreNameMismatch);
390391

391392
// If there was no such argument, leave the parameter unfulfilled.
392393
if (!claimed) {
@@ -407,7 +408,8 @@ matchCallArguments(SmallVectorImpl<AnyFunctionType::Param> &args,
407408
{
408409
nextArgIdx = *claimed;
409410
// Claim any additional unnamed arguments.
410-
while ((claimed = claimNextNamed(Identifier(), false, true))) {
411+
while (
412+
(claimed = claimNextNamed(nextArgIdx, Identifier(), false, true))) {
411413
parameterBindings[paramIdx].push_back(*claimed);
412414
}
413415
}
@@ -417,7 +419,8 @@ matchCallArguments(SmallVectorImpl<AnyFunctionType::Param> &args,
417419
}
418420

419421
// Try to claim an argument for this parameter.
420-
if (auto claimed = claimNextNamed(param.getLabel(), ignoreNameMismatch)) {
422+
if (auto claimed =
423+
claimNextNamed(nextArgIdx, param.getLabel(), ignoreNameMismatch)) {
421424
parameterBindings[paramIdx].push_back(*claimed);
422425
return;
423426
}
@@ -480,10 +483,13 @@ matchCallArguments(SmallVectorImpl<AnyFunctionType::Param> &args,
480483
parameterBindings[lastParamIdx].push_back(numArgs - 1);
481484
}
482485

483-
// Mark through the parameters, binding them to their arguments.
484-
for (paramIdx = 0; paramIdx != numParams; ++paramIdx) {
485-
if (parameterBindings[paramIdx].empty())
486-
bindNextParameter(false);
486+
{
487+
unsigned nextArgIdx = 0;
488+
// Mark through the parameters, binding them to their arguments.
489+
for (paramIdx = 0; paramIdx != numParams; ++paramIdx) {
490+
if (parameterBindings[paramIdx].empty())
491+
bindNextParameter(nextArgIdx, false);
492+
}
487493
}
488494

489495
// If we have any unclaimed arguments, complain about those.
@@ -560,14 +566,14 @@ matchCallArguments(SmallVectorImpl<AnyFunctionType::Param> &args,
560566
// semi-positionally.
561567
if (numClaimedArgs != numArgs) {
562568
// Restart at the first argument/parameter.
563-
nextArgIdx = 0;
569+
unsigned nextArgIdx = 0;
564570
haveUnfulfilledParams = false;
565571
for (paramIdx = 0; paramIdx != numParams; ++paramIdx) {
566572
// Skip fulfilled parameters.
567573
if (!parameterBindings[paramIdx].empty())
568574
continue;
569575

570-
bindNextParameter(true);
576+
bindNextParameter(nextArgIdx, true);
571577
}
572578
}
573579

0 commit comments

Comments
 (0)