summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJan Kotas <jkotas@microsoft.com>2018-03-27 07:06:36 -0700
committerGitHub <noreply@github.com>2018-03-27 07:06:36 -0700
commitc0fbb148fbc435122f1d439658aa1b9a7ee3f333 (patch)
tree86e633b577c27fe6954b003e1e1c586287c741ab
parent6ecb1ac550ec1876094264cdbdd629c1a832ebee (diff)
downloadcoreclr-c0fbb148fbc435122f1d439658aa1b9a7ee3f333.tar.gz
coreclr-c0fbb148fbc435122f1d439658aa1b9a7ee3f333.tar.bz2
coreclr-c0fbb148fbc435122f1d439658aa1b9a7ee3f333.zip
Move String.Comparison.cs to shared CoreLib partition (#17247)
-rw-r--r--src/mscorlib/System.Private.CoreLib.csproj1
-rw-r--r--src/mscorlib/shared/System.Private.CoreLib.Shared.projitems1
-rw-r--r--src/mscorlib/shared/System/String.Comparison.cs (renamed from src/mscorlib/src/System/String.Comparison.cs)112
3 files changed, 52 insertions, 62 deletions
diff --git a/src/mscorlib/System.Private.CoreLib.csproj b/src/mscorlib/System.Private.CoreLib.csproj
index 27e5702d31..a32d2e3249 100644
--- a/src/mscorlib/System.Private.CoreLib.csproj
+++ b/src/mscorlib/System.Private.CoreLib.csproj
@@ -322,7 +322,6 @@
<Compile Include="$(BclSourcesRoot)\System\Array.cs" />
<Compile Include="$(BclSourcesRoot)\System\ThrowHelper.cs" />
<Compile Include="$(BclSourcesRoot)\System\String.CoreCLR.cs" />
- <Compile Include="$(BclSourcesRoot)\System\String.Comparison.cs" />
<Compile Include="$(BclSourcesRoot)\System\Text\StringBuilder.CoreCLR.cs" />
<Compile Include="$(BclSourcesRoot)\System\Text\StringBuilderCache.cs" />
<Compile Include="$(BclSourcesRoot)\System\Exception.cs" />
diff --git a/src/mscorlib/shared/System.Private.CoreLib.Shared.projitems b/src/mscorlib/shared/System.Private.CoreLib.Shared.projitems
index 4f7e0614e3..1143580173 100644
--- a/src/mscorlib/shared/System.Private.CoreLib.Shared.projitems
+++ b/src/mscorlib/shared/System.Private.CoreLib.Shared.projitems
@@ -495,6 +495,7 @@
<Compile Include="$(MSBuildThisFileDirectory)System\SpanHelpers.Char.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\SpanHelpers.T.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\String.cs" />
+ <Compile Include="$(MSBuildThisFileDirectory)System\String.Comparison.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\String.Manipulation.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\String.Searching.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\StackOverflowException.cs" />
diff --git a/src/mscorlib/src/System/String.Comparison.cs b/src/mscorlib/shared/System/String.Comparison.cs
index 34c20ba7dd..2a8be32d3f 100644
--- a/src/mscorlib/src/System/String.Comparison.cs
+++ b/src/mscorlib/shared/System/String.Comparison.cs
@@ -2,11 +2,9 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
-using System.Collections;
using System.Diagnostics;
using System.Globalization;
using System.Runtime.CompilerServices;
-using System.Runtime.ConstrainedExecution;
using System.Runtime.InteropServices;
using Internal.Runtime.CompilerServices;
@@ -21,7 +19,7 @@ namespace System
{
public partial class String
{
- private static unsafe int CompareOrdinalIgnoreCaseHelper(String strA, String strB)
+ private static unsafe int CompareOrdinalIgnoreCaseHelper(string strA, string strB)
{
Debug.Assert(strA != null);
Debug.Assert(strB != null);
@@ -62,7 +60,7 @@ namespace System
//
[MethodImpl(MethodImplOptions.AggressiveInlining)]
- private static bool EqualsHelper(String strA, String strB)
+ private static bool EqualsHelper(string strA, string strB)
{
Debug.Assert(strA != null);
Debug.Assert(strB != null);
@@ -75,7 +73,7 @@ namespace System
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
- private static int CompareOrdinalHelper(String strA, int indexA, int countA, String strB, int indexB, int countB)
+ private static int CompareOrdinalHelper(string strA, int indexA, int countA, string strB, int indexB, int countB)
{
Debug.Assert(strA != null);
Debug.Assert(strB != null);
@@ -86,7 +84,7 @@ namespace System
return SpanHelpers.SequenceCompareTo(ref Unsafe.Add(ref strA.GetRawStringData(), indexA), countA, ref Unsafe.Add(ref strB.GetRawStringData(), indexB), countB);
}
- private static unsafe bool EqualsIgnoreCaseAsciiHelper(String strA, String strB)
+ private static unsafe bool EqualsIgnoreCaseAsciiHelper(string strA, string strB)
{
Debug.Assert(strA != null);
Debug.Assert(strB != null);
@@ -124,7 +122,7 @@ namespace System
}
}
- private static unsafe int CompareOrdinalHelper(String strA, String strB)
+ private static unsafe int CompareOrdinalHelper(string strA, string strB)
{
Debug.Assert(strA != null);
Debug.Assert(strB != null);
@@ -152,9 +150,8 @@ namespace System
// and 64-bit (16 bytes) platforms.
// For empty strings, the second char will be null due to padding.
- // The start of the string (not including sync block pointer)
- // is the method table pointer + string length, which takes up
- // 8 bytes on 32-bit, 12 on x64. For empty strings the null
+ // The start of the string is the type pointer + string length, which
+ // takes up 8 bytes on 32-bit, 12 on x64. For empty strings the null
// terminator immediately follows, leaving us with an object
// 10/14 bytes in size. Since everything needs to be a multiple
// of 4/8, this will get padded and zeroed out.
@@ -248,7 +245,7 @@ namespace System
// to determine whether it is lexicographically less, equal, or greater, and then returns
// either a negative integer, 0, or a positive integer; respectively.
//
- public static int Compare(String strA, String strB)
+ public static int Compare(string strA, string strB)
{
return Compare(strA, strB, StringComparison.CurrentCulture);
}
@@ -259,16 +256,16 @@ namespace System
// negative integer, 0, or a positive integer is returned; respectively.
// The case-sensitive option is set by ignoreCase
//
- public static int Compare(String strA, String strB, bool ignoreCase)
+ public static int Compare(string strA, string strB, bool ignoreCase)
{
var comparisonType = ignoreCase ? StringComparison.CurrentCultureIgnoreCase : StringComparison.CurrentCulture;
return Compare(strA, strB, comparisonType);
}
- // Provides a more flexible function for string comparision. See StringComparison
+ // Provides a more flexible function for string comparison. See StringComparison
// for meaning of different comparisonType.
- public static int Compare(String strA, String strB, StringComparison comparisonType)
+ public static int Compare(string strA, string strB, StringComparison comparisonType)
{
if (object.ReferenceEquals(strA, strB))
{
@@ -332,7 +329,7 @@ namespace System
// to determine whether it is lexicographically less, equal, or greater, and then a
// negative integer, 0, or a positive integer is returned; respectively.
//
- public static int Compare(String strA, String strB, CultureInfo culture, CompareOptions options)
+ public static int Compare(string strA, string strB, CultureInfo culture, CompareOptions options)
{
if (culture == null)
{
@@ -350,17 +347,17 @@ namespace System
// The case-sensitive option is set by ignoreCase, and the culture is set
// by culture
//
- public static int Compare(String strA, String strB, bool ignoreCase, CultureInfo culture)
+ public static int Compare(string strA, string strB, bool ignoreCase, CultureInfo culture)
{
var options = ignoreCase ? CompareOptions.IgnoreCase : CompareOptions.None;
return Compare(strA, strB, culture, options);
}
// Determines whether two string regions match. The substring of strA beginning
- // at indexA of length count is compared with the substring of strB
+ // at indexA of given length is compared with the substring of strB
// beginning at indexB of the same length.
//
- public static int Compare(String strA, int indexA, String strB, int indexB, int length)
+ public static int Compare(string strA, int indexA, string strB, int indexB, int length)
{
// NOTE: It's important we call the boolean overload, and not the StringComparison
// one. The two have some subtly different behavior (see notes in the former).
@@ -368,10 +365,10 @@ namespace System
}
// Determines whether two string regions match. The substring of strA beginning
- // at indexA of length count is compared with the substring of strB
+ // at indexA of given length is compared with the substring of strB
// beginning at indexB of the same length. Case sensitivity is determined by the ignoreCase boolean.
//
- public static int Compare(String strA, int indexA, String strB, int indexB, int length, bool ignoreCase)
+ public static int Compare(string strA, int indexA, string strB, int indexB, int length, bool ignoreCase)
{
// Ideally we would just forward to the string.Compare overload that takes
// a StringComparison parameter, and just pass in CurrentCulture/CurrentCultureIgnoreCase.
@@ -409,7 +406,7 @@ namespace System
// beginning at indexB of the same length. Case sensitivity is determined by the ignoreCase boolean,
// and the culture is set by culture.
//
- public static int Compare(String strA, int indexA, String strB, int indexB, int length, bool ignoreCase, CultureInfo culture)
+ public static int Compare(string strA, int indexA, string strB, int indexB, int length, bool ignoreCase, CultureInfo culture)
{
var options = ignoreCase ? CompareOptions.IgnoreCase : CompareOptions.None;
return Compare(strA, indexA, strB, indexB, length, culture, options);
@@ -420,7 +417,7 @@ namespace System
// at indexA of length length is compared with the substring of strB
// beginning at indexB of the same length.
//
- public static int Compare(String strA, int indexA, String strB, int indexB, int length, CultureInfo culture, CompareOptions options)
+ public static int Compare(string strA, int indexA, string strB, int indexB, int length, CultureInfo culture, CompareOptions options)
{
if (culture == null)
{
@@ -443,7 +440,7 @@ namespace System
return culture.CompareInfo.Compare(strA, indexA, lengthA, strB, indexB, lengthB, options);
}
- public static int Compare(String strA, int indexA, String strB, int indexB, int length, StringComparison comparisonType)
+ public static int Compare(string strA, int indexA, string strB, int indexB, int length, StringComparison comparisonType)
{
CheckStringComparison(comparisonType);
@@ -511,7 +508,7 @@ namespace System
// Compares strA and strB using an ordinal (code-point) comparison.
//
- public static int CompareOrdinal(String strA, String strB)
+ public static int CompareOrdinal(string strA, string strB)
{
if (object.ReferenceEquals(strA, strB))
{
@@ -544,7 +541,7 @@ namespace System
// Compares strA and strB using an ordinal (code-point) comparison.
//
- public static int CompareOrdinal(String strA, int indexA, String strB, int indexB, int length)
+ public static int CompareOrdinal(string strA, int indexA, string strB, int indexB, int length)
{
if (strA == null || strB == null)
{
@@ -592,7 +589,7 @@ namespace System
// indicates the relationship. This method returns a value less than 0 if this is less than value, 0
// if this is equal to value, or a value greater than 0 if this is greater than value.
//
- public int CompareTo(Object value)
+ public int CompareTo(object value)
{
if (value == null)
{
@@ -611,7 +608,7 @@ namespace System
// Determines the sorting relation of StrB to the current instance.
//
- public int CompareTo(String strB)
+ public int CompareTo(string strB)
{
return string.Compare(this, strB, StringComparison.CurrentCulture);
}
@@ -621,19 +618,19 @@ namespace System
// The case-sensitive and culture-sensitive option is set by options,
// and the default culture is used.
//
- public Boolean EndsWith(String value)
+ public bool EndsWith(string value)
{
return EndsWith(value, StringComparison.CurrentCulture);
}
- public Boolean EndsWith(String value, StringComparison comparisonType)
+ public bool EndsWith(string value, StringComparison comparisonType)
{
- if ((Object)value == null)
+ if ((object)value == null)
{
throw new ArgumentNullException(nameof(value));
}
- if ((Object)this == (Object)value)
+ if ((object)this == (object)value)
{
CheckStringComparison(comparisonType);
return true;
@@ -670,7 +667,7 @@ namespace System
}
}
- public Boolean EndsWith(String value, Boolean ignoreCase, CultureInfo culture)
+ public bool EndsWith(string value, bool ignoreCase, CultureInfo culture)
{
if (null == value)
{
@@ -693,7 +690,7 @@ namespace System
}
// Determines whether two strings match.
- public override bool Equals(Object obj)
+ public override bool Equals(object obj)
{
if (object.ReferenceEquals(this, obj))
return true;
@@ -709,7 +706,7 @@ namespace System
}
// Determines whether two strings match.
- public bool Equals(String value)
+ public bool Equals(string value)
{
if (object.ReferenceEquals(this, value))
return true;
@@ -727,15 +724,15 @@ namespace System
return EqualsHelper(this, value);
}
- public bool Equals(String value, StringComparison comparisonType)
+ public bool Equals(string value, StringComparison comparisonType)
{
- if ((Object)this == (Object)value)
+ if ((object)this == (object)value)
{
CheckStringComparison(comparisonType);
return true;
}
- if ((Object)value == null)
+ if ((object)value == null)
{
CheckStringComparison(comparisonType);
return false;
@@ -779,14 +776,14 @@ namespace System
// Determines whether two Strings match.
- public static bool Equals(String a, String b)
+ public static bool Equals(string a, string b)
{
- if ((Object)a == (Object)b)
+ if ((object)a == (object)b)
{
return true;
}
- if ((Object)a == null || (Object)b == null || a.Length != b.Length)
+ if ((object)a == null || (object)b == null || a.Length != b.Length)
{
return false;
}
@@ -794,15 +791,15 @@ namespace System
return EqualsHelper(a, b);
}
- public static bool Equals(String a, String b, StringComparison comparisonType)
+ public static bool Equals(string a, string b, StringComparison comparisonType)
{
- if ((Object)a == (Object)b)
+ if ((object)a == (object)b)
{
CheckStringComparison(comparisonType);
return true;
}
- if ((Object)a == null || (Object)b == null)
+ if ((object)a == null || (object)b == null)
{
CheckStringComparison(comparisonType);
return false;
@@ -844,14 +841,14 @@ namespace System
}
}
- public static bool operator ==(String a, String b)
+ public static bool operator ==(string a, string b)
{
- return String.Equals(a, b);
+ return string.Equals(a, b);
}
- public static bool operator !=(String a, String b)
+ public static bool operator !=(string a, string b)
{
- return !String.Equals(a, b);
+ return !string.Equals(a, b);
}
// Gets a hash code for this string. If strings A and B are such that A.Equals(B), then
@@ -862,7 +859,7 @@ namespace System
}
// Gets a hash code for this string and this comparison. If strings A and B and comparison C are such
- // that String.Equals(A, B, C), then they will return the same hash code with this comparison C.
+ // that string.Equals(A, B, C), then they will return the same hash code with this comparison C.
public int GetHashCode(StringComparison comparisonType) => StringComparer.FromComparison(comparisonType).GetHashCode(this);
// Use this if and only if you need the hashcode to not change across app domains (e.g. you have an app domain agile
@@ -911,13 +908,6 @@ namespace System
hash1 = ((hash1 << 5) + hash1 + (hash1 >> 27)) ^ pint[0];
}
#endif
-#if DEBUG
- // We want to ensure we can change our hash function daily.
- // This is perfectly fine as long as you don't persist the
- // value from GetHashCode to disk or count on String A
- // hashing before string B. Those are bugs in your code.
- hash1 ^= ThisAssembly.DailyBuildNumber;
-#endif
return hash1 + (hash2 * 1566083941);
}
}
@@ -925,23 +915,23 @@ namespace System
// Determines whether a specified string is a prefix of the current instance
//
- public Boolean StartsWith(String value)
+ public bool StartsWith(string value)
{
- if ((Object)value == null)
+ if ((object)value == null)
{
throw new ArgumentNullException(nameof(value));
}
return StartsWith(value, StringComparison.CurrentCulture);
}
- public Boolean StartsWith(String value, StringComparison comparisonType)
+ public bool StartsWith(string value, StringComparison comparisonType)
{
- if ((Object)value == null)
+ if ((object)value == null)
{
throw new ArgumentNullException(nameof(value));
}
- if ((Object)this == (Object)value)
+ if ((object)this == (object)value)
{
CheckStringComparison(comparisonType);
return true;
@@ -991,7 +981,7 @@ namespace System
}
}
- public Boolean StartsWith(String value, Boolean ignoreCase, CultureInfo culture)
+ public bool StartsWith(string value, bool ignoreCase, CultureInfo culture)
{
if (null == value)
{