[System.Private.CoreLib] Cleanup intrinsic tracking (#17884)
[mono-project.git] / netcore / System.Private.CoreLib / src / System / String.Mono.cs
bloba4b8526bcfb6afae3c9d1061de464a30816e683c
1 // Licensed to the .NET Foundation under one or more agreements.
2 // The .NET Foundation licenses this file to you under the MIT license.
3 // See the LICENSE file in the project root for more information.
5 using System.Runtime.CompilerServices;
6 using Internal.Runtime.CompilerServices;
8 namespace System
10 partial class String
12 [Intrinsic]
13 public static readonly String Empty;
15 public int Length {
16 [Intrinsic]
17 get => _stringLength;
20 [IndexerName ("Chars")]
21 public char this [int index] {
22 [Intrinsic]
23 get => this [index];
26 public static String Intern (String str)
28 if (str == null)
29 throw new ArgumentNullException(nameof(str));
31 return InternalIntern (str);
34 public static String IsInterned (String str)
36 if (str == null)
37 throw new ArgumentNullException(nameof(str));
39 return InternalIsInterned (str);
42 [MethodImplAttribute (MethodImplOptions.InternalCall)]
43 internal extern static String FastAllocateString (int length);
45 [MethodImplAttribute (MethodImplOptions.InternalCall)]
46 extern static String InternalIsInterned (String str);
48 [MethodImplAttribute (MethodImplOptions.InternalCall)]
49 extern static String InternalIntern (String str);
51 // TODO: Should be pointing to Buffer instead
52 #region Runtime method-to-ir dependencies
54 static unsafe void memset (byte *dest, int val, int len)
56 if (len < 8) {
57 while (len != 0) {
58 *dest = (byte)val;
59 ++dest;
60 --len;
62 return;
64 if (val != 0) {
65 val = val | (val << 8);
66 val = val | (val << 16);
68 // align to 4
69 int rest = (int)dest & 3;
70 if (rest != 0) {
71 rest = 4 - rest;
72 len -= rest;
73 do {
74 *dest = (byte)val;
75 ++dest;
76 --rest;
77 } while (rest != 0);
79 while (len >= 16) {
80 ((int*)dest) [0] = val;
81 ((int*)dest) [1] = val;
82 ((int*)dest) [2] = val;
83 ((int*)dest) [3] = val;
84 dest += 16;
85 len -= 16;
87 while (len >= 4) {
88 ((int*)dest) [0] = val;
89 dest += 4;
90 len -= 4;
92 // tail bytes
93 while (len > 0) {
94 *dest = (byte)val;
95 dest++;
96 len--;
100 static unsafe void memcpy (byte *dest, byte *src, int size)
102 Buffer.Memcpy (dest, src, size);
105 /* Used by the runtime */
106 internal static unsafe void bzero (byte *dest, int len) {
107 memset (dest, 0, len);
110 internal static unsafe void bzero_aligned_1 (byte *dest, int len) {
111 ((byte*)dest) [0] = 0;
114 internal static unsafe void bzero_aligned_2 (byte *dest, int len) {
115 ((short*)dest) [0] = 0;
118 internal static unsafe void bzero_aligned_4 (byte *dest, int len) {
119 ((int*)dest) [0] = 0;
122 internal static unsafe void bzero_aligned_8 (byte *dest, int len) {
123 ((long*)dest) [0] = 0;
126 internal static unsafe void memcpy_aligned_1 (byte *dest, byte *src, int size) {
127 ((byte*)dest) [0] = ((byte*)src) [0];
130 internal static unsafe void memcpy_aligned_2 (byte *dest, byte *src, int size) {
131 ((short*)dest) [0] = ((short*)src) [0];
134 internal static unsafe void memcpy_aligned_4 (byte *dest, byte *src, int size) {
135 ((int*)dest) [0] = ((int*)src) [0];
138 internal static unsafe void memcpy_aligned_8 (byte *dest, byte *src, int size) {
139 ((long*)dest) [0] = ((long*)src) [0];
142 #endregion
144 // Certain constructors are redirected to CreateString methods with
145 // matching argument list. The this pointer should not be used.
147 // TODO: Update runtime to call Ctor directly
149 unsafe String CreateString (sbyte* value)
151 return Ctor (value);
154 unsafe String CreateString (sbyte* value, int startIndex, int length)
156 return Ctor (value, startIndex, length);
159 unsafe String CreateString (char* value)
161 return Ctor (value);
164 unsafe String CreateString (char* value, int startIndex, int length)
166 return Ctor (value, startIndex, length);
169 String CreateString (char[] val, int startIndex, int length)
171 return Ctor (val, startIndex, length);
174 String CreateString (char [] val)
176 return Ctor (val);
179 String CreateString (char c, int count)
181 return Ctor (c, count);
184 unsafe String CreateString (sbyte* value, int startIndex, int length, System.Text.Encoding enc)
186 return Ctor (value, startIndex, length, enc);
189 String CreateString (ReadOnlySpan<char> value)
191 return Ctor (value);