Skip to content

Commit

Permalink
[corlib] Use String from CoreCLR
Browse files Browse the repository at this point in the history
  • Loading branch information
marek-safar committed Jul 12, 2018
1 parent 262c5f4 commit 74e23f6
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 44 deletions.
2 changes: 1 addition & 1 deletion external/corert
2 changes: 2 additions & 0 deletions mcs/class/corlib/ReferenceSources/String.cs
Expand Up @@ -59,6 +59,8 @@ partial class String

public static readonly String Empty;

public int Length => _stringLength;

internal unsafe int IndexOfUnchecked (string value, int startIndex, int count)
{
int valueLen = value.Length;
Expand Down
40 changes: 4 additions & 36 deletions mcs/class/corlib/Test/System/StringTest.cs
Expand Up @@ -348,15 +348,7 @@ public unsafe void Constructor7_Value_Invalid ()
[Test] // ctor (SByte*, Int32, Int32)
public unsafe void Constructor7_Value_Null ()
{
try {
new String ((sbyte*) null, 0, 0);
Assert.Fail ("#A1");
} catch (ArgumentNullException ex) {
Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#A2");
Assert.IsNull (ex.InnerException, "#A3");
Assert.IsNotNull (ex.Message, "#A4");
Assert.AreEqual ("value", ex.ParamName, "#A5");
}
Assert.AreEqual (string.Empty, new String ((sbyte*) null, 0, 0));

try {
new String ((sbyte*) null, 0, 1);
Expand All @@ -368,15 +360,7 @@ public unsafe void Constructor7_Value_Null ()
Assert.AreEqual ("value", ex.ParamName, "#B5");
}

try {
new String ((sbyte*) null, 1, 0);
Assert.Fail ("#C1");
} catch (ArgumentNullException ex) {
Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#C2");
Assert.IsNull (ex.InnerException, "#C3");
Assert.IsNotNull (ex.Message, "#C4");
Assert.AreEqual ("value", ex.ParamName, "#C5");
}
Assert.AreEqual (string.Empty, new String ((sbyte*) null, 1, 0));
}

[Test] // ctor (SByte*, Int32, Int32, Encoding)
Expand Down Expand Up @@ -511,15 +495,7 @@ public unsafe void Constructor8_Value_Invalid2 ()
[Test] // ctor (SByte*, Int32, Int32, Encoding)
public unsafe void Constructor8_Value_Null ()
{
try {
new String ((sbyte*) null, 0, 0, null);
Assert.Fail ("#A1");
} catch (ArgumentNullException ex) {
Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#A2");
Assert.IsNull (ex.InnerException, "#A3");
Assert.IsNotNull (ex.Message, "#A4");
Assert.AreEqual ("value", ex.ParamName, "#A5");
}
Assert.AreEqual (string.Empty, new String ((sbyte*) null, 0, 0, null));

try {
new String ((sbyte*) null, 0, 1, null);
Expand All @@ -531,15 +507,7 @@ public unsafe void Constructor8_Value_Null ()
Assert.AreEqual ("value", ex.ParamName, "#B5");
}

try {
new String ((sbyte*) null, 1, 0, null);
Assert.Fail ("#C1");
} catch (ArgumentNullException ex) {
Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#C2");
Assert.IsNull (ex.InnerException, "#C3");
Assert.IsNotNull (ex.Message, "#C4");
Assert.AreEqual ("value", ex.ParamName, "#C5");
}
Assert.AreEqual (string.Empty, new String ((sbyte*) null, 1, 0, null));

Assert.AreEqual (String.Empty, new String ((sbyte*) null, 0, 0, Encoding.Default), "#D");

Expand Down
4 changes: 4 additions & 0 deletions mcs/class/corlib/corefx/SR.missing.cs
@@ -0,0 +1,4 @@
partial class SR
{
public const string Arg_MustBeNullTerminatedString = "The string must be null-terminated.";
}
6 changes: 3 additions & 3 deletions mcs/class/corlib/corlib.dll.sources
Expand Up @@ -891,7 +891,6 @@ ReferenceSources/Type.cs
../referencesource/mscorlib/system/_localdatastore.cs
../referencesource/mscorlib/system/_localdatastoremgr.cs
../referencesource/mscorlib/system/accessviolationexception.cs
../referencesource/mscorlib/system/action.cs
../referencesource/mscorlib/system/activator.cs
../referencesource/mscorlib/system/AggregateException.cs
../referencesource/mscorlib/system/appdomainattributes.cs
Expand Down Expand Up @@ -1540,6 +1539,7 @@ coreclr/SorterArray.cs
corefx/AwaitTaskContinuation.cs
corefx/SynchronizationContext.cs
corefx/SR.cs
corefx/SR.missing.cs
corefx/CompareInfo.cs
corefx/GlobalizationMode.cs
corefx/Interop.GetRandomBytes.Mono.cs
Expand Down Expand Up @@ -1570,8 +1570,6 @@ corert/RuntimeAugments.cs
../../../external/corert/src/System.Private.CoreLib/src/System/Array.cs
../../../external/corert/src/System.Private.CoreLib/src/System/ByReference.cs
# TODO: Should all come from shared
../../../external/corert/src/System.Private.CoreLib/src/System/String.cs

../../../external/corert/src/System.Private.CoreLib/src/System/Collections/Generic/ArraySortHelper.cs

../../../external/corert/src/System.Private.CoreLib/src/System/Globalization/GlobalizationMode.cs
Expand Down Expand Up @@ -1608,6 +1606,7 @@ corert/RuntimeAugments.cs
../../../external/corefx/src/System.ObjectModel/src/System/Collections/ObjectModel/KeyedCollection.cs
../../../external/corefx/src/System.ObjectModel/src/System/Collections/ObjectModel/ReadOnlyDictionary.cs

../../../external/corefx/src/Common/src/CoreLib/System/Action.cs
../../../external/corefx/src/Common/src/CoreLib/System/ArraySegment.cs
../../../external/corefx/src/Common/src/CoreLib/System/Gen2GcCallback.cs
../../../external/corefx/src/Common/src/CoreLib/System/HashCode.cs
Expand All @@ -1628,6 +1627,7 @@ corert/RuntimeAugments.cs
../../../external/corefx/src/Common/src/CoreLib/System/SpanHelpers.BinarySearch.cs
../../../external/corefx/src/Common/src/CoreLib/System/SpanHelpers.Byte.cs
../../../external/corefx/src/Common/src/CoreLib/System/SpanHelpers.T.cs
../../../external/corefx/src/Common/src/CoreLib/System/String.cs
../../../external/corefx/src/Common/src/CoreLib/System/String.Comparison.cs
../../../external/corefx/src/Common/src/CoreLib/System/String.Manipulation.cs
../../../external/corefx/src/Common/src/CoreLib/System/String.Searching.cs
Expand Down
6 changes: 3 additions & 3 deletions mcs/class/referencesource/mscorlib/system/text/encoding.cs
Expand Up @@ -1370,16 +1370,16 @@ public unsafe string GetString(byte* bytes, int byteCount)
#if MONO
public virtual unsafe int GetChars(ReadOnlySpan<byte> bytes, Span<char> chars)
{
fixed (byte* bytesPtr = &System.Runtime.InteropServices.MemoryMarshal.GetReference(bytes))
fixed (char* charsPtr = &System.Runtime.InteropServices.MemoryMarshal.GetReference(chars))
fixed (byte* bytesPtr = &System.Runtime.InteropServices.MemoryMarshal.GetNonNullPinnableReference(bytes))
fixed (char* charsPtr = &System.Runtime.InteropServices.MemoryMarshal.GetNonNullPinnableReference(chars))
{
return GetChars(bytesPtr, bytes.Length, charsPtr, chars.Length);
}
}

public unsafe string GetString(ReadOnlySpan<byte> bytes)
{
fixed (byte* bytesPtr = &bytes.GetPinnableReference())
fixed (byte* bytesPtr = &System.Runtime.InteropServices.MemoryMarshal.GetNonNullPinnableReference(bytes))
{
return GetString(bytesPtr, bytes.Length);
}
Expand Down

0 comments on commit 74e23f6

Please sign in to comment.