Skip to content

Commit

Permalink
Use Array.Empty<T>() (#1210)
Browse files Browse the repository at this point in the history
Use Array.Empty<string>() instead of allocating a new array if either of the strings for comparison are null.
  • Loading branch information
martincostello authored and Tratcher committed Mar 4, 2019
1 parent a064ef3 commit afb772f
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/Configuration/Config/src/ConfigurationKeyComparer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ public class ConfigurationKeyComparer : IComparer<string>
/// <returns></returns>
public int Compare(string x, string y)
{
var xParts = x?.Split(_keyDelimiterArray, StringSplitOptions.RemoveEmptyEntries) ?? new string[0];
var yParts = y?.Split(_keyDelimiterArray, StringSplitOptions.RemoveEmptyEntries) ?? new string[0];
var xParts = x?.Split(_keyDelimiterArray, StringSplitOptions.RemoveEmptyEntries) ?? Array.Empty<string>();
var yParts = y?.Split(_keyDelimiterArray, StringSplitOptions.RemoveEmptyEntries) ?? Array.Empty<string>();

// Compare each part until we get two parts that are not equal
for (int i = 0; i < Math.Min(xParts.Length, yParts.Length); i++)
Expand All @@ -41,7 +41,7 @@ public int Compare(string x, string y)
var xIsInt = x != null && int.TryParse(x, out value1);
var yIsInt = y != null && int.TryParse(y, out value2);

int result = 0;
int result;

if (!xIsInt && !yIsInt)
{
Expand Down

0 comments on commit afb772f

Please sign in to comment.