Make TypeNameParser consistently use tabs
[mono-project.git] / netcore / System.Private.CoreLib / src / System / String.cs
blob56b63403c3e7d756d21f810d5fea6f25ad941a0c
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 [NonSerialized]
13 int _stringLength;
14 [NonSerialized]
15 char _firstChar;
17 [Intrinsic]
18 public static readonly String Empty;
20 public int Length => _stringLength;
22 [IndexerName ("Chars")]
23 public char this [int index] {
24 [Intrinsic]
25 get {
26 if ((uint)index >= _stringLength)
27 ThrowHelper.ThrowIndexOutOfRangeException ();
29 return Unsafe.Add (ref _firstChar, index);
33 public static String Intern (String str)
35 if (str == null)
36 throw new ArgumentNullException(nameof(str));
38 return InternalIntern (str);
41 public static String IsInterned (String str)
43 if (str == null)
44 throw new ArgumentNullException(nameof(str));
46 return InternalIsInterned (str);
49 [MethodImplAttribute (MethodImplOptions.InternalCall)]
50 internal extern static String FastAllocateString (int length);
52 [MethodImplAttribute (MethodImplOptions.InternalCall)]
53 extern static String InternalIsInterned (String str);
55 [MethodImplAttribute (MethodImplOptions.InternalCall)]
56 extern static String InternalIntern (String str);
58 // TODO: Should be pointing to Buffer instead
59 #region Runtime method-to-ir dependencies
61 static unsafe void memset (byte *dest, int val, int len)
63 if (len < 8) {
64 while (len != 0) {
65 *dest = (byte)val;
66 ++dest;
67 --len;
69 return;
71 if (val != 0) {
72 val = val | (val << 8);
73 val = val | (val << 16);
75 // align to 4
76 int rest = (int)dest & 3;
77 if (rest != 0) {
78 rest = 4 - rest;
79 len -= rest;
80 do {
81 *dest = (byte)val;
82 ++dest;
83 --rest;
84 } while (rest != 0);
86 while (len >= 16) {
87 ((int*)dest) [0] = val;
88 ((int*)dest) [1] = val;
89 ((int*)dest) [2] = val;
90 ((int*)dest) [3] = val;
91 dest += 16;
92 len -= 16;
94 while (len >= 4) {
95 ((int*)dest) [0] = val;
96 dest += 4;
97 len -= 4;
99 // tail bytes
100 while (len > 0) {
101 *dest = (byte)val;
102 dest++;
103 len--;
107 static unsafe void memcpy (byte *dest, byte *src, int size)
109 Buffer.Memcpy (dest, src, size);
112 /* Used by the runtime */
113 internal static unsafe void bzero (byte *dest, int len) {
114 memset (dest, 0, len);
117 internal static unsafe void bzero_aligned_1 (byte *dest, int len) {
118 ((byte*)dest) [0] = 0;
121 internal static unsafe void bzero_aligned_2 (byte *dest, int len) {
122 ((short*)dest) [0] = 0;
125 internal static unsafe void bzero_aligned_4 (byte *dest, int len) {
126 ((int*)dest) [0] = 0;
129 internal static unsafe void bzero_aligned_8 (byte *dest, int len) {
130 ((long*)dest) [0] = 0;
133 internal static unsafe void memcpy_aligned_1 (byte *dest, byte *src, int size) {
134 ((byte*)dest) [0] = ((byte*)src) [0];
137 internal static unsafe void memcpy_aligned_2 (byte *dest, byte *src, int size) {
138 ((short*)dest) [0] = ((short*)src) [0];
141 internal static unsafe void memcpy_aligned_4 (byte *dest, byte *src, int size) {
142 ((int*)dest) [0] = ((int*)src) [0];
145 internal static unsafe void memcpy_aligned_8 (byte *dest, byte *src, int size) {
146 ((long*)dest) [0] = ((long*)src) [0];
149 #endregion
151 // Certain constructors are redirected to CreateString methods with
152 // matching argument list. The this pointer should not be used.
154 // TODO: Update runtime to call Ctor directly
156 unsafe String CreateString (sbyte* value)
158 return Ctor (value);
161 unsafe String CreateString (sbyte* value, int startIndex, int length)
163 return Ctor (value, startIndex, length);
166 unsafe String CreateString (char* value)
168 return Ctor (value);
171 unsafe String CreateString (char* value, int startIndex, int length)
173 return Ctor (value, startIndex, length);
176 String CreateString (char[] val, int startIndex, int length)
178 return Ctor (val, startIndex, length);
181 String CreateString (char [] val)
183 return Ctor (val);
186 String CreateString (char c, int count)
188 return Ctor (c, count);
191 unsafe String CreateString (sbyte* value, int startIndex, int length, System.Text.Encoding enc)
193 return Ctor (value, startIndex, length, enc);
196 String CreateString (ReadOnlySpan<char> value)
198 return Ctor (value);