diff options
Diffstat (limited to 'mcs/class/corlib/System/String.cs')
-rw-r--r-- | mcs/class/corlib/System/String.cs | 91 |
1 files changed, 17 insertions, 74 deletions
diff --git a/mcs/class/corlib/System/String.cs b/mcs/class/corlib/System/String.cs index c29798450ee..822a6803a6a 100644 --- a/mcs/class/corlib/System/String.cs +++ b/mcs/class/corlib/System/String.cs @@ -72,42 +72,28 @@ namespace System if (len != b.length) return false; - fixed (char* s1 = &a.start_char, s2 = &b.start_char) { - char* s1_ptr = s1; - char* s2_ptr = s2; - - while (len >= 8) { - if (((int*)s1_ptr)[0] != ((int*)s2_ptr)[0] || - ((int*)s1_ptr)[1] != ((int*)s2_ptr)[1] || - ((int*)s1_ptr)[2] != ((int*)s2_ptr)[2] || - ((int*)s1_ptr)[3] != ((int*)s2_ptr)[3]) - return false; - - s1_ptr += 8; - s2_ptr += 8; - len -= 8; - } - - if (len >= 4) { - if (((int*)s1_ptr)[0] != ((int*)s2_ptr)[0] || - ((int*)s1_ptr)[1] != ((int*)s2_ptr)[1]) - return false; + if (len == 0) + return true; - s1_ptr += 4; - s2_ptr += 4; - len -= 4; - } + fixed (char * s1 = &a.start_char, s2 = &b.start_char) { + // it must be one char, because 0 len is done above + if (len < 2) + return *s1 == *s2; - if (len > 1) { - if (((int*)s1_ptr)[0] != ((int*)s2_ptr)[0]) + // check by twos + int * sint1 = (int *) s1, sint2 = (int *) s2; + int n2 = len >> 1; + do { + if (*sint1++ != *sint2++) return false; + } while (--n2 != 0); - s1_ptr += 2; - s2_ptr += 2; - len -= 2; - } + // nothing left + if ((len & 1) == 0) + return true; - return len == 0 || *s1_ptr == *s2_ptr; + // check the last one + return *(char *) sint1 == *(char *) sint2; } } @@ -939,49 +925,6 @@ namespace System } #if NET_2_0 - public bool StartsWith (string value, StringComparison comparisonType) - { - switch (comparisonType) { - case StringComparison.CurrentCulture: - return CultureInfo.CurrentCulture.CompareInfo.IsPrefix (this, value, CompareOptions.None); - case StringComparison.CurrentCultureIgnoreCase: - return CultureInfo.CurrentCulture.CompareInfo.IsPrefix (this, value, CompareOptions.IgnoreCase); - case StringComparison.InvariantCulture: - return CultureInfo.InvariantCulture.CompareInfo.IsPrefix (this, value, CompareOptions.None); - case StringComparison.InvariantCultureIgnoreCase: - return CultureInfo.InvariantCulture.CompareInfo.IsPrefix (this, value, CompareOptions.IgnoreCase); - case StringComparison.Ordinal: - return CultureInfo.CurrentCulture.CompareInfo.IsPrefix (this, value, CompareOptions.Ordinal); - case StringComparison.OrdinalIgnoreCase: - return CultureInfo.CurrentCulture.CompareInfo.IsPrefix (this, value, CompareOptions.OrdinalIgnoreCase); - default: - return false; - } - } - - public bool EndsWith (string value, StringComparison comparisonType) - { - switch (comparisonType) { - case StringComparison.CurrentCulture: - return CultureInfo.CurrentCulture.CompareInfo.IsSuffix (this, value, CompareOptions.None); - case StringComparison.CurrentCultureIgnoreCase: - return CultureInfo.CurrentCulture.CompareInfo.IsSuffix (this, value, CompareOptions.IgnoreCase); - case StringComparison.InvariantCulture: - return CultureInfo.InvariantCulture.CompareInfo.IsSuffix (this, value, CompareOptions.None); - case StringComparison.InvariantCultureIgnoreCase: - return CultureInfo.InvariantCulture.CompareInfo.IsSuffix (this, value, CompareOptions.IgnoreCase); - case StringComparison.Ordinal: - return CultureInfo.CurrentCulture.CompareInfo.IsSuffix (this, value, CompareOptions.Ordinal); - case StringComparison.OrdinalIgnoreCase: - return CultureInfo.CurrentCulture.CompareInfo.IsSuffix (this, value, CompareOptions.OrdinalIgnoreCase); - default: - return false; - } - } - -#endif - -#if NET_2_0 public #else internal |