Skip to content

Commit 07b1b17

Browse files
authored
Perf improvements part 5.1 (#1601)
1 parent 467df57 commit 07b1b17

File tree

16 files changed

+253
-544
lines changed

16 files changed

+253
-544
lines changed

src/System.CommandLine.ApiCompatibility.Tests/ApiCompatibilityApprovalTests.System_CommandLine_api_is_not_changed.approved.txt

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -50,12 +50,14 @@
5050
public class Command : IdentifierSymbol, System.Collections.Generic.IEnumerable<Symbol>, System.Collections.IEnumerable, System.CommandLine.Completions.ICompletionSource
5151
.ctor(System.String name, System.String description = null)
5252
public System.Collections.Generic.IReadOnlyList<Argument> Arguments { get; }
53-
public System.CommandLine.Collections.SymbolSet Children { get; }
53+
public System.Collections.Generic.IEnumerable<Symbol> Children { get; }
5454
public System.CommandLine.Invocation.ICommandHandler Handler { get; set; }
5555
public System.Collections.Generic.IReadOnlyList<Option> Options { get; }
56+
public System.Collections.Generic.IReadOnlyList<Command> Subcommands { get; }
5657
public System.Boolean TreatUnmatchedTokensAsErrors { get; set; }
57-
public System.Void Add(Symbol symbol)
58+
public System.Void Add(Option option)
5859
public System.Void Add(Argument argument)
60+
public System.Void Add(Command command)
5961
public System.Void AddArgument(Argument argument)
6062
public System.Void AddCommand(Command command)
6163
public System.Void AddGlobalOption(Option option)
@@ -77,7 +79,6 @@
7779
public System.Boolean EnablePosixBundling { get; }
7880
public LocalizationResources LocalizationResources { get; }
7981
public Command RootCommand { get; }
80-
public System.CommandLine.Collections.SymbolSet Symbols { get; }
8182
public System.Void ThrowIfInvalid()
8283
public class CommandLineConfigurationException : System.Exception, System.Runtime.Serialization.ISerializable
8384
.ctor(System.String message)
@@ -283,12 +284,6 @@ System.CommandLine.Builder
283284
public static CommandLineBuilder UseTypoCorrections(this CommandLineBuilder builder, System.Int32 maxLevenshteinDistance = 3)
284285
public static CommandLineBuilder UseVersionOption(this CommandLineBuilder builder)
285286
public static CommandLineBuilder UseVersionOption(this CommandLineBuilder builder, System.String[] aliases)
286-
System.CommandLine.Collections
287-
public class SymbolSet, System.Collections.Generic.IEnumerable<System.CommandLine.Symbol>, System.Collections.Generic.IReadOnlyCollection<System.CommandLine.Symbol>, System.Collections.Generic.IReadOnlyList<System.CommandLine.Symbol>, System.Collections.IEnumerable
288-
.ctor()
289-
public System.Int32 Count { get; }
290-
public System.CommandLine.Symbol Item { get; }
291-
public System.Collections.Generic.IEnumerator<System.CommandLine.Symbol> GetEnumerator()
292287
System.CommandLine.Completions
293288
public abstract class CompletionContext
294289
public System.CommandLine.Parsing.ParseResult ParseResult { get; }

src/System.CommandLine.Benchmarks/CommandLine/Perf_Parser_NestedCommands.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,9 @@ public void SetupRootCommand()
5656

5757
// Choose only one path from the commands tree for the test arguments string
5858
Command currentCmd = rootCommand;
59-
while (currentCmd is not null && currentCmd.Children.Count > 0)
59+
while (currentCmd is not null && currentCmd.Subcommands.Count > 0)
6060
{
61-
currentCmd = currentCmd.Children[0] as Command;
61+
currentCmd = currentCmd.Subcommands[0];
6262
_testSymbolsAsString = string.Join(" ", _testSymbolsAsString, currentCmd.Name);
6363
}
6464

src/System.CommandLine.Benchmarks/CommandLine/Perf_Parser_Options_Bare.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ namespace System.CommandLine.Benchmarks.CommandLine
1515
[BenchmarkCategory(Categories.CommandLine)]
1616
public class Perf_Parser_Options_Bare
1717
{
18-
private IEnumerable<Symbol> _testSymbols;
18+
private IEnumerable<Option> _testSymbols;
1919
private string _testSymbolsAsString;
2020
private Parser _testParser;
2121

src/System.CommandLine.Benchmarks/Helpers/Utils.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ internal static string CreateTestAssemblyInTempFileFromString(string sourceCode,
4444
return pathToAssemblyFile;
4545
}
4646

47-
public static Parser CreateParser(this IEnumerable<Symbol> symbols)
47+
public static Parser CreateParser(this IEnumerable<Option> symbols)
4848
{
4949
var rootCommand = new RootCommand();
5050

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
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.CommandLine.Collections;
4+
using System.Collections.Generic;
55
using System.Linq;
66

77
namespace System.CommandLine.Tests
88
{
99
internal static class SymbolSetExtensions
1010
{
11-
internal static Symbol GetByAlias(this SymbolSet symbolSet, string alias)
11+
internal static Symbol GetByAlias(this IEnumerable<Symbol> symbolSet, string alias)
1212
=> symbolSet.SingleOrDefault(symbol => symbol.Name.Equals(alias) || symbol is IdentifierSymbol id && id.HasAlias(alias));
1313

14-
internal static bool ContainsAlias(this SymbolSet symbolSet, string alias)
14+
internal static bool ContainsAlias(this IEnumerable<Symbol> symbolSet, string alias)
1515
=> symbolSet.OfType<IdentifierSymbol>().Any(symbol => symbol.HasAlias(alias));
1616
}
1717
}

src/System.CommandLine.Tests/SymbolSetTests.cs

Lines changed: 0 additions & 189 deletions
This file was deleted.

src/System.CommandLine/Collections/SymbolSet.cs

Lines changed: 0 additions & 98 deletions
This file was deleted.

0 commit comments

Comments
 (0)