|
10 | 10 | using System.Runtime.InteropServices;
|
11 | 11 | #endif
|
12 | 12 | using Microsoft.Toolkit.HighPerformance.Extensions;
|
| 13 | +using Microsoft.Toolkit.HighPerformance.Helpers.Internals; |
13 | 14 | #if !SPAN_RUNTIME_SUPPORT
|
14 | 15 | using RuntimeHelpers = Microsoft.Toolkit.HighPerformance.Helpers.Internals.RuntimeHelpers;
|
15 | 16 | #endif
|
@@ -151,14 +152,8 @@ public readonly void Clear()
|
151 | 152 | ref T r0 = ref RuntimeHelpers.GetObjectDataAtOffsetOrPointerReference<T>(this.instance, this.offset);
|
152 | 153 | int length = this.length;
|
153 | 154 | #endif
|
154 |
| - nint |
155 |
| - step = (nint)(uint)this.step, |
156 |
| - offset = 0; |
157 | 155 |
|
158 |
| - for (int i = length; i > 0; i--, offset += step) |
159 |
| - { |
160 |
| - Unsafe.Add(ref r0, offset) = default!; |
161 |
| - } |
| 156 | + RefEnumerableHelper.Clear(ref r0, (nint)(uint)length, (nint)(uint)this.step); |
162 | 157 | }
|
163 | 158 |
|
164 | 159 | /// <summary>
|
@@ -190,14 +185,8 @@ public readonly void CopyTo(Span<T> destination)
|
190 | 185 | }
|
191 | 186 |
|
192 | 187 | ref T destinationRef = ref destination.DangerousGetReference();
|
193 |
| - nint |
194 |
| - step = (nint)(uint)this.step, |
195 |
| - offset = 0; |
196 | 188 |
|
197 |
| - for (int i = 0; i < length; i++, offset += step) |
198 |
| - { |
199 |
| - Unsafe.Add(ref destinationRef, i) = Unsafe.Add(ref sourceRef, offset); |
200 |
| - } |
| 189 | + RefEnumerableHelper.CopyTo(ref sourceRef, ref destinationRef, (nint)(uint)length, (nint)(uint)this.step); |
201 | 190 | }
|
202 | 191 |
|
203 | 192 | /// <summary>
|
@@ -254,14 +243,7 @@ internal readonly void CopyFrom(ReadOnlySpan<T> source)
|
254 | 243 | ThrowArgumentExceptionForDestinationTooShort();
|
255 | 244 | }
|
256 | 245 |
|
257 |
| - nint |
258 |
| - step = (nint)(uint)this.step, |
259 |
| - offset = 0; |
260 |
| - |
261 |
| - for (int i = 0; i < sourceLength; i++, offset += step) |
262 |
| - { |
263 |
| - Unsafe.Add(ref destinationRef, i) = Unsafe.Add(ref sourceRef, offset); |
264 |
| - } |
| 246 | + RefEnumerableHelper.CopyFrom(ref sourceRef, ref destinationRef, (nint)(uint)sourceLength, (nint)(uint)this.step); |
265 | 247 | }
|
266 | 248 |
|
267 | 249 | /// <summary>
|
@@ -312,14 +294,7 @@ public readonly void Fill(T value)
|
312 | 294 | int length = this.length;
|
313 | 295 | #endif
|
314 | 296 |
|
315 |
| - nint |
316 |
| - step = (nint)(uint)this.step, |
317 |
| - offset = 0; |
318 |
| - |
319 |
| - for (int i = length; i > 0; i--, offset += step) |
320 |
| - { |
321 |
| - Unsafe.Add(ref r0, offset) = value; |
322 |
| - } |
| 297 | + RefEnumerableHelper.Fill(ref r0, (nint)(uint)length, (nint)(uint)this.step, value); |
323 | 298 | }
|
324 | 299 |
|
325 | 300 | /// <summary>
|
|
0 commit comments