Просмотр исходного кода

Use faster versions of string comparers

Marek Safar 13 лет назад
Родитель
Сommit
a336b58fdc

+ 1 - 1
mcs/class/corlib/System.IO/DriveInfo.cs

@@ -51,7 +51,7 @@ namespace System.IO {
 					throw new ArgumentException ("Invalid drive name", "driveName");
 
 				// Convert the path to a standard format so we can find it later.
-				driveName = String.Concat (Char.ToUpper (driveName [0]).ToString (), ":\\");
+				driveName = String.Concat (Char.ToUpperInvariant (driveName [0]).ToString (), ":\\");
 			}
 
 			DriveInfo [] drives = GetDrives ();

+ 4 - 4
mcs/class/corlib/System/Boolean.cs

@@ -170,10 +170,10 @@ namespace System
 
 			value = value.Trim ();
 
-			if (String.Compare (value, TrueString, true, CultureInfo.InvariantCulture) == 0)
+			if (string.CompareOrdinalCaseInsensitive (value, TrueString) == 0)
 				return true;
 
-			if (String.Compare (value, FalseString, true, CultureInfo.InvariantCulture) == 0)
+			if (string.CompareOrdinalCaseInsensitive (value, FalseString) == 0)
 				return false;
 
 			throw new FormatException (Locale.GetText (
@@ -188,12 +188,12 @@ namespace System
 
 			value = value.Trim ();
 
-			if (String.Compare (value, TrueString, true, CultureInfo.InvariantCulture) == 0) {
+			if (string.CompareOrdinalCaseInsensitive (value, TrueString) == 0) {
 				result = true;
 				return true;
 			}
 
-			if (String.Compare (value, FalseString, true, CultureInfo.InvariantCulture) == 0) {
+			if (string.CompareOrdinalCaseInsensitive (value, FalseString) == 0) {
 				// result = false; // already set at false by default
 				return true;
 			}

+ 1 - 1
mcs/class/corlib/System/DateTime.cs

@@ -1046,7 +1046,7 @@ namespace System
 			if (maxlength <= 0)
 				maxlength = value.Length;
 
-			if (sPos + maxlength <= s.Length && String.Compare (s, sPos, value, 0, maxlength, true, CultureInfo.InvariantCulture) == 0) {
+			if (sPos + maxlength <= s.Length && String.CompareOrdinalCaseInsensitive (s, sPos, value, 0, maxlength) == 0) {
 				num_parsed = maxlength;
 				return true;
 			}

+ 1 - 2
mcs/class/corlib/System/Decimal.cs

@@ -1073,8 +1073,7 @@ namespace System
 			len = s.Length;
 			if (len >= max + 1) {
 				// number lower than MaxValue (base-less) can have better precision
-				if (String.Compare (s, 0, "79228162514264337593543950335", 0, max + 1,
-					false, CultureInfo.InvariantCulture) <= 0) {
+				if (String.CompareOrdinal (s, 0, "79228162514264337593543950335", 0, max + 1) <= 0) {
 					max++;
 				}
 			}

+ 10 - 2
mcs/class/corlib/System/String.cs

@@ -710,12 +710,12 @@ namespace System
 
 		public static bool Equals (string a, string b, StringComparison comparisonType)
 		{
-			return String.Compare (a, b, comparisonType) == 0;
+			return Compare (a, b, comparisonType) == 0;
 		}
 
 		public bool Equals (string value, StringComparison comparisonType)
 		{
-			return String.Compare (value, this, comparisonType) == 0;
+			return Compare (value, this, comparisonType) == 0;
 		}
 
 		public static int Compare (string strA, string strB, CultureInfo culture, CompareOptions options)
@@ -825,6 +825,14 @@ namespace System
 			}
 		}
 
+		//
+		// Fastest method for internal case insensitive comparison
+		//
+		internal static int CompareOrdinalCaseInsensitive (string strA, string strB)
+		{
+			return CompareOrdinalCaseInsensitiveUnchecked (strA, 0, int.MaxValue, strB, 0, int.MaxValue);
+		}
+
 		internal static unsafe int CompareOrdinalCaseInsensitiveUnchecked (String strA, int indexA, int lenA, String strB, int indexB, int lenB)
 		{
 			// Same as above, but checks versus uppercase characters