From 16fb54da31ac71ad7027e3f112d2fe325310f395 Mon Sep 17 00:00:00 2001 From: Oliver Booth Date: Thu, 14 Jan 2021 18:18:30 +0000 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=8E=20Improve=20performancee=20on=20st?= =?UTF-8?q?ring.IsUpper()?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Item for #12 --- X10D/src/StringExtensions.cs | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/X10D/src/StringExtensions.cs b/X10D/src/StringExtensions.cs index aa05785..fbf506f 100644 --- a/X10D/src/StringExtensions.cs +++ b/X10D/src/StringExtensions.cs @@ -192,14 +192,27 @@ /// /// Determines if all alpha characters in this string are considered uppercase. /// - /// The input string. + /// The input string. /// /// Returns if all alpha characters are uppercase, /// otherwise. /// - 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; } ///