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
;
13 public static readonly String Empty
;
20 [IndexerName ("Chars")]
21 public char this [int index
] {
26 public static String
Intern (String str
)
29 throw new ArgumentNullException(nameof(str
));
31 return InternalIntern (str
);
34 public static String
IsInterned (String str
)
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
)
65 val
= val
| (val
<< 8);
66 val
= val
| (val
<< 16);
69 int rest
= (int)dest
& 3;
80 ((int*)dest
) [0] = val
;
81 ((int*)dest
) [1] = val
;
82 ((int*)dest
) [2] = val
;
83 ((int*)dest
) [3] = val
;
88 ((int*)dest
) [0] = val
;
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];
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)
154 unsafe String
CreateString (sbyte* value, int startIndex
, int length
)
156 return Ctor (value, startIndex
, length
);
159 unsafe String
CreateString (char* 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
)
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)