Skip to content

Commit 1813871

Browse files
authored
don't use Value Tuples as they are expensive for startup perf (#2163)
1 parent 723cd2c commit 1813871

File tree

1 file changed

+10
-22
lines changed

1 file changed

+10
-22
lines changed

src/System.CommandLine/Invocation/InvocationPipeline.cs

Lines changed: 10 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
// Copyright (c) .NET Foundation and contributors. All rights reserved.
22
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
33

4-
using System.Linq;
54
using System.Threading;
65
using System.Threading.Tasks;
76

@@ -23,10 +22,9 @@ internal static async Task<int> InvokeAsync(ParseResult parseResult, Cancellatio
2322
{
2423
if (parseResult.NonexclusiveActions is not null)
2524
{
26-
for (var i = 0; i < parseResult.NonexclusiveActions.Count; i++)
25+
for (int i = 0; i < parseResult.NonexclusiveActions.Count; i++)
2726
{
28-
var action = parseResult.NonexclusiveActions[i];
29-
await action.InvokeAsync(parseResult, cts.Token);
27+
await parseResult.NonexclusiveActions[i].InvokeAsync(parseResult, cts.Token);
3028
}
3129
}
3230

@@ -67,31 +65,21 @@ internal static int Invoke(ParseResult parseResult)
6765
return ReturnCodeForMissingAction(parseResult);
6866
}
6967

70-
if (parseResult.NonexclusiveActions is not null)
68+
try
7169
{
72-
for (var i = 0; i < parseResult.NonexclusiveActions.Count; i++)
70+
if (parseResult.NonexclusiveActions is not null)
7371
{
74-
var action = parseResult.NonexclusiveActions[i];
75-
var result = TryInvokeAction(parseResult, action);
76-
if (!result.success)
72+
for (var i = 0; i < parseResult.NonexclusiveActions.Count; i++)
7773
{
78-
return result.returnCode;
74+
parseResult.NonexclusiveActions[i].Invoke(parseResult);
7975
}
8076
}
81-
}
82-
83-
return TryInvokeAction(parseResult, parseResult.Action).returnCode;
8477

85-
static (int returnCode, bool success) TryInvokeAction(ParseResult parseResult, CliAction action)
78+
return parseResult.Action.Invoke(parseResult);
79+
}
80+
catch (Exception ex) when (parseResult.Configuration.EnableDefaultExceptionHandler)
8681
{
87-
try
88-
{
89-
return (action.Invoke(parseResult), true);
90-
}
91-
catch (Exception ex) when (parseResult.Configuration.EnableDefaultExceptionHandler)
92-
{
93-
return (DefaultExceptionHandler(ex, parseResult.Configuration), false);
94-
}
82+
return DefaultExceptionHandler(ex, parseResult.Configuration);
9583
}
9684
}
9785

0 commit comments

Comments
 (0)