Skip to content

don't use Value Tuples as they are expensive for startup perf #2163

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 12, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 10 additions & 22 deletions src/System.CommandLine/Invocation/InvocationPipeline.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// Copyright (c) .NET Foundation and contributors. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

using System.Linq;
using System.Threading;
using System.Threading.Tasks;

Expand All @@ -23,10 +22,9 @@ internal static async Task<int> InvokeAsync(ParseResult parseResult, Cancellatio
{
if (parseResult.NonexclusiveActions is not null)
{
for (var i = 0; i < parseResult.NonexclusiveActions.Count; i++)
for (int i = 0; i < parseResult.NonexclusiveActions.Count; i++)
{
var action = parseResult.NonexclusiveActions[i];
await action.InvokeAsync(parseResult, cts.Token);
await parseResult.NonexclusiveActions[i].InvokeAsync(parseResult, cts.Token);
}
}

Expand Down Expand Up @@ -67,31 +65,21 @@ internal static int Invoke(ParseResult parseResult)
return ReturnCodeForMissingAction(parseResult);
}

if (parseResult.NonexclusiveActions is not null)
try
{
for (var i = 0; i < parseResult.NonexclusiveActions.Count; i++)
if (parseResult.NonexclusiveActions is not null)
{
var action = parseResult.NonexclusiveActions[i];
var result = TryInvokeAction(parseResult, action);
if (!result.success)
for (var i = 0; i < parseResult.NonexclusiveActions.Count; i++)
{
return result.returnCode;
parseResult.NonexclusiveActions[i].Invoke(parseResult);
}
}
}

return TryInvokeAction(parseResult, parseResult.Action).returnCode;

static (int returnCode, bool success) TryInvokeAction(ParseResult parseResult, CliAction action)
return parseResult.Action.Invoke(parseResult);
}
catch (Exception ex) when (parseResult.Configuration.EnableDefaultExceptionHandler)
{
try
{
return (action.Invoke(parseResult), true);
}
catch (Exception ex) when (parseResult.Configuration.EnableDefaultExceptionHandler)
{
return (DefaultExceptionHandler(ex, parseResult.Configuration), false);
}
return DefaultExceptionHandler(ex, parseResult.Configuration);
}
}

Expand Down