Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[corlib] Use String from CoreCLR #9134

Merged
merged 4 commits into from Jul 15, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This means we are not expecting an ArgumentNullException anymore, correct?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

correct


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 @@ -1625,6 +1624,7 @@ corert/RuntimeAugments.cs
../../../external/corefx/src/Common/src/CoreLib/System/Span.Fast.cs
../../../external/corefx/src/Common/src/CoreLib/System/SpanDebugView.cs
../../../external/corefx/src/Common/src/CoreLib/System/SpanHelpers*.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