🐎 Improve performancee on string.IsUpper()

Item for #12
This commit is contained in:
Oliver Booth 2021-01-14 18:18:30 +00:00
parent 14f600666b
commit 16fb54da31
1 changed files with 16 additions and 3 deletions

View File

@ -192,14 +192,27 @@
/// <summary> /// <summary>
/// Determines if all alpha characters in this string are considered uppercase. /// Determines if all alpha characters in this string are considered uppercase.
/// </summary> /// </summary>
/// <param name="str">The input string.</param> /// <param name="value">The input string.</param>
/// <returns> /// <returns>
/// Returns <see langword="true" /> if all alpha characters are uppercase, <see langword="false" /> /// Returns <see langword="true" /> if all alpha characters are uppercase, <see langword="false" />
/// otherwise. /// otherwise.
/// </returns> /// </returns>
public static bool IsUpper(this string str) public static bool IsUpper(this string value)
{ {
return str.Where(char.IsLetter).All(char.IsUpper); for (var index = 0; index < value.Length; index++)
{
if (!char.IsLetter(value[index]))
{
continue;
}
if (!char.IsUpper(value[index]))
{
return false;
}
}
return true;
} }
/// <summary> /// <summary>