diff options
author | Marek Safar <marek.safar@gmail.com> | 2018-03-02 12:33:02 +0300 |
---|---|---|
committer | Jan Kotas <jkotas@microsoft.com> | 2018-03-02 12:33:02 +0300 |
commit | 5ae871ca2298c8caaf8966204360f5b67c5404bb (patch) | |
tree | 14935388540f260db86eb734d06c088b90151311 | |
parent | fb52cf9bd5edca3077073efbed138ddf211017a3 (diff) |
Move CoreRT specific String class bits to its own file (#5478)
-rw-r--r-- | src/System.Private.CoreLib/src/System.Private.CoreLib.csproj | 1 | ||||
-rw-r--r-- | src/System.Private.CoreLib/src/System/String.CoreRT.cs | 85 | ||||
-rw-r--r-- | src/System.Private.CoreLib/src/System/String.cs | 64 |
3 files changed, 86 insertions, 64 deletions
diff --git a/src/System.Private.CoreLib/src/System.Private.CoreLib.csproj b/src/System.Private.CoreLib/src/System.Private.CoreLib.csproj index bd1371f69..9f041c462 100644 --- a/src/System.Private.CoreLib/src/System.Private.CoreLib.csproj +++ b/src/System.Private.CoreLib/src/System.Private.CoreLib.csproj @@ -273,6 +273,7 @@ <Compile Include="System\Runtime\Serialization\SerializationInfo.cs" /> <Compile Include="System\String.cs" /> <Compile Include="System\String.Comparison.cs" /> + <Compile Include="System\String.CoreRT.cs" /> <Compile Include="System\String.Intern.cs" /> <Compile Include="System\Array.cs" /> <Compile Include="System\Array.CoreRT.cs" /> diff --git a/src/System.Private.CoreLib/src/System/String.CoreRT.cs b/src/System.Private.CoreLib/src/System/String.CoreRT.cs new file mode 100644 index 000000000..a892006d9 --- /dev/null +++ b/src/System.Private.CoreLib/src/System/String.CoreRT.cs @@ -0,0 +1,85 @@ +// Licensed to the .NET Foundation under one or more agreements. +// 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.Collections.Generic; +using System.Diagnostics; +using System.Globalization; +using System.Runtime; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; +using System.Runtime.Versioning; +using System.Text; + +using Internal.Runtime.CompilerServices; + +namespace System +{ + [StructLayout(LayoutKind.Sequential)] + [System.Runtime.CompilerServices.EagerStaticClassConstructionAttribute] + [System.Runtime.CompilerServices.TypeForwardedFrom("mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")] + public partial class String + { +#if BIT64 + private const int POINTER_SIZE = 8; +#else + private const int POINTER_SIZE = 4; +#endif + // m_pEEType + _stringLength + internal const int FIRST_CHAR_OFFSET = POINTER_SIZE + sizeof(int); + + // CS0169: The private field '{blah}' is never used + // CS0649: Field '{blah}' is never assigned to, and will always have its default value +#pragma warning disable 169, 649 + +#if PROJECTN + [Bound] +#endif + // WARNING: We allow diagnostic tools to directly inspect these two members (_stringLength, _firstChar) + // See https://github.com/dotnet/corert/blob/master/Documentation/design-docs/diagnostics/diagnostics-tools-contract.md for more details. + // Please do not change the type, the name, or the semantic usage of this member without understanding the implication for tools. + // Get in touch with the diagnostics team if you have questions. + [NonSerialized] + private int _stringLength; + [NonSerialized] + private char _firstChar; + +#pragma warning restore + + public static readonly String Empty = ""; + + // Gets the character at a specified position. + // + // Spec#: Apply the precondition here using a contract assembly. Potential perf issue. + [System.Runtime.CompilerServices.IndexerName("Chars")] + public unsafe char this[int index] + { +#if PROJECTN + [BoundsChecking] + get + { + return Unsafe.Add(ref _firstChar, index); + } +#else + [Intrinsic] + get + { + if ((uint)index >= _stringLength) + ThrowHelper.ThrowIndexOutOfRangeException(); + return Unsafe.Add(ref _firstChar, index); + } +#endif + } + + internal static String FastAllocateString(int length) + { + // We allocate one extra char as an interop convenience so that our strings are null- + // terminated, however, we don't pass the extra +1 to the string allocation because the base + // size of this object includes the _firstChar field. + string newStr = RuntimeImports.RhNewString(EETypePtr.EETypePtrOf<string>(), length); + Debug.Assert(newStr._stringLength == length); + return newStr; + } + } +} diff --git a/src/System.Private.CoreLib/src/System/String.cs b/src/System.Private.CoreLib/src/System/String.cs index 076bd02a8..6c0f7532b 100644 --- a/src/System.Private.CoreLib/src/System/String.cs +++ b/src/System.Private.CoreLib/src/System/String.cs @@ -74,38 +74,9 @@ namespace System // constructed itself depends on this class also being eagerly constructed. Plus, it's nice to have this // eagerly constructed to avoid the cost of defered ctors. I can't imagine any app that doesn't use string // - [StructLayout(LayoutKind.Sequential)] - [System.Runtime.CompilerServices.EagerStaticClassConstructionAttribute] [Serializable] - [System.Runtime.CompilerServices.TypeForwardedFrom("mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")] public sealed partial class String : IComparable, IEnumerable, IEnumerable<char>, IComparable<String>, IEquatable<String>, IConvertible, ICloneable { -#if BIT64 - private const int POINTER_SIZE = 8; -#else - private const int POINTER_SIZE = 4; -#endif - // m_pEEType + _stringLength - internal const int FIRST_CHAR_OFFSET = POINTER_SIZE + sizeof(int); - - // CS0169: The private field '{blah}' is never used - // CS0649: Field '{blah}' is never assigned to, and will always have its default value -#pragma warning disable 169, 649 - -#if PROJECTN - [Bound] -#endif - // WARNING: We allow diagnostic tools to directly inspect these two members (_stringLength, _firstChar) - // See https://github.com/dotnet/corert/blob/master/Documentation/design-docs/diagnostics/diagnostics-tools-contract.md for more details. - // Please do not change the type, the name, or the semantic usage of this member without understanding the implication for tools. - // Get in touch with the diagnostics team if you have questions. - [NonSerialized] - private int _stringLength; - [NonSerialized] - private char _firstChar; - -#pragma warning restore - // String constructors // These are special. the implementation methods for these have a different signature from the // declared constructors. @@ -464,31 +435,6 @@ namespace System return result; } - public static readonly String Empty = ""; - - // Gets the character at a specified position. - // - // Spec#: Apply the precondition here using a contract assembly. Potential perf issue. - [System.Runtime.CompilerServices.IndexerName("Chars")] - public unsafe char this[int index] - { -#if PROJECTN - [BoundsChecking] - get - { - return Unsafe.Add(ref _firstChar, index); - } -#else - [Intrinsic] - get - { - if ((uint)index >= _stringLength) - ThrowHelper.ThrowIndexOutOfRangeException(); - return Unsafe.Add(ref _firstChar, index); - } -#endif - } - // Converts a substring of this string to an array of characters. Copies the // characters of this string beginning at position sourceIndex and ending at // sourceIndex + count - 1 to the character array buffer, beginning @@ -630,16 +576,6 @@ namespace System return result; } - internal static String FastAllocateString(int length) - { - // We allocate one extra char as an interop convenience so that our strings are null- - // terminated, however, we don't pass the extra +1 to the string allocation because the base - // size of this object includes the _firstChar field. - string newStr = RuntimeImports.RhNewString(EETypePtr.EETypePtrOf<string>(), length); - Debug.Assert(newStr._stringLength == length); - return newStr; - } - internal static unsafe void wstrcpy(char* dmem, char* smem, int charCount) { Buffer.Memmove((byte*)dmem, (byte*)smem, ((uint)charCount) * 2); |