Skip to content

Commit

Permalink
Improve performance.
Browse files Browse the repository at this point in the history
  • Loading branch information
kingcean committed Nov 19, 2024
1 parent 903c501 commit 085959c
Show file tree
Hide file tree
Showing 30 changed files with 1,378 additions and 547 deletions.
23 changes: 20 additions & 3 deletions Core/Collection/List/ListExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -357,9 +357,7 @@ public static bool TryGetValue<TKey, TValue>(this IList<KeyValuePair<TKey, TValu
/// <returns>The value. The first one for multiple values.</returns>
/// <exception cref="IndexOutOfRangeException">index is less than 0, or is equals to or greater than the length of the values of the specific key.</exception>
public static TValue GetValue<TKey, TValue>(this IEnumerable<KeyValuePair<TKey, TValue>> list, TKey key, int index)
{
return GetValues(list, key).ToList()[index];
}
=> GetValues(list, key).ToList()[index];

/// <summary>
/// Gets the value by a specific key.
Expand Down Expand Up @@ -643,6 +641,24 @@ public static int Remove<TKey, TValue>(this List<KeyValuePair<TKey, TValue>> lis
return count;
}

/// <summary>
/// Removes all the elements by the specific key.
/// </summary>
/// <param name="list">The key value pairs.</param>
/// <param name="keys">The keys to remove.</param>
/// <returns>The number of elements removed from the key value pairs.</returns>
public static int Remove<TKey, TValue>(this List<KeyValuePair<TKey, TValue>> list, params ReadOnlySpan<TKey> keys)
{
if (list == null) throw ObjectConvert.ArgumentNull(nameof(list));
var count = 0;
foreach (var key in keys)
{
count = key == null ? list.RemoveAll(item => item.Key == null) : list.RemoveAll(item => key.Equals(item.Key));
}

return count;
}

/// <summary>
/// Searches for the specified key and returns the zero-based index of the last occurrence within the entire key value pairs.
/// </summary>
Expand Down Expand Up @@ -1059,6 +1075,7 @@ public static IList<T> ToSynchronizedList<T>(IEnumerable<T> list, object syncRoo
/// <returns>A synchronized list.</returns>
public static IList<T> ToSynchronizedList<T>(List<T> list, object syncRoot, bool useSource)
=> new ConcurrentList<T>(syncRoot, list, useSource);

/// <summary>
/// Determines whether it contains the property only with the specific key.
/// </summary>
Expand Down
4 changes: 1 addition & 3 deletions Core/CommandLine/Args/CommandArguments.cs
Original file line number Diff line number Diff line change
Expand Up @@ -169,9 +169,7 @@ public string this[string key]
/// <param name="additionalKeys">The additional keys including alias and short name.</param>
/// <returns>A set of parameter.</returns>
public CommandParameters Get(string key, params string[] additionalKeys)
{
return Get(key, additionalKeys as IEnumerable<string>);
}
=> Get(key, additionalKeys as IEnumerable<string>);

/// <summary>
/// Gets the specific parameters by key.
Expand Down
13 changes: 13 additions & 0 deletions Core/CommandLine/Console/Text.cs
Original file line number Diff line number Diff line change
Expand Up @@ -545,6 +545,19 @@ public void Append(string s, int start, int count)
public void AppendFormat(string format, params object[] args)
=> Content.AppendFormat(format, args);

#if NET9_0_OR_GREATER
/// <summary>
/// Appends the string returned by processing a composite format string, which contains zero or more format items, to this instance. Each format item is replaced by the string representation of a corresponding argument in a parameter array.
/// </summary>
/// <param name="format">A composite format string.</param>
/// <param name="args">An array of objects to format.</param>
/// <exception cref="ArgumentNullException">format or args is null.</exception>
/// <exception cref="FormatException">format is invalid. -or- The index of a format item is less than 0 (zero), or greater than or equal to the length of the args array.</exception>
/// <exception cref="ArgumentOutOfRangeException">The length of the expanded string would exceed System.Text.StringBuilder.MaxCapacity.</exception>
public void AppendFormat(string format, params ReadOnlySpan<object> args)
=> Content.AppendFormat(format, args);
#endif

/// <summary>
/// Returns a string with ANSI escape sequences that represents the content.
/// </summary>
Expand Down
Loading

0 comments on commit 085959c

Please sign in to comment.