File tree Expand file tree Collapse file tree 2 files changed +8
-4
lines changed
src/libraries/System.Private.CoreLib/src/System Expand file tree Collapse file tree 2 files changed +8
-4
lines changed Original file line number Diff line number Diff line change @@ -263,7 +263,7 @@ public Memory<T> Slice(int start, int length)
263
263
/// <summary>
264
264
/// Returns a span from the memory.
265
265
/// </summary>
266
- public unsafe Span < T > Span
266
+ public Span < T > Span
267
267
{
268
268
[ MethodImpl ( MethodImplOptions . AggressiveInlining ) ]
269
269
get
@@ -327,7 +327,9 @@ public unsafe Span<T> Span
327
327
// least to be in-bounds when compared with the original Memory<T> instance, so using the span won't
328
328
// AV the process.
329
329
330
+ // We use 'nuint' because it gives us a free early zero-extension to 64 bits when running on a 64-bit platform.
330
331
nuint desiredStartIndex = ( uint ) _index & ( uint ) ReadOnlyMemory < T > . RemoveFlagsBitMask ;
332
+
331
333
int desiredLength = _length ;
332
334
333
335
#if TARGET_64BIT
@@ -343,7 +345,7 @@ public unsafe Span<T> Span
343
345
}
344
346
#endif
345
347
346
- refToReturn = ref Unsafe . Add ( ref refToReturn , ( IntPtr ) ( void * ) desiredStartIndex ) ;
348
+ refToReturn = ref Unsafe . Add ( ref refToReturn , desiredStartIndex ) ;
347
349
lengthOfUnderlyingSpan = desiredLength ;
348
350
}
349
351
Original file line number Diff line number Diff line change @@ -192,7 +192,7 @@ public ReadOnlyMemory<T> Slice(int start, int length)
192
192
/// <summary>
193
193
/// Returns a span from the memory.
194
194
/// </summary>
195
- public unsafe ReadOnlySpan < T > Span
195
+ public ReadOnlySpan < T > Span
196
196
{
197
197
[ MethodImpl ( MethodImplOptions . AggressiveInlining ) ]
198
198
get
@@ -249,7 +249,9 @@ public unsafe ReadOnlySpan<T> Span
249
249
// least to be in-bounds when compared with the original Memory<T> instance, so using the span won't
250
250
// AV the process.
251
251
252
+ // We use 'nuint' because it gives us a free early zero-extension to 64 bits when running on a 64-bit platform.
252
253
nuint desiredStartIndex = ( uint ) _index & ( uint ) RemoveFlagsBitMask ;
254
+
253
255
int desiredLength = _length ;
254
256
255
257
#if TARGET_64BIT
@@ -265,7 +267,7 @@ public unsafe ReadOnlySpan<T> Span
265
267
}
266
268
#endif
267
269
268
- refToReturn = ref Unsafe . Add ( ref refToReturn , ( IntPtr ) ( void * ) desiredStartIndex ) ;
270
+ refToReturn = ref Unsafe . Add ( ref refToReturn , desiredStartIndex ) ;
269
271
lengthOfUnderlyingSpan = desiredLength ;
270
272
}
271
273
You can’t perform that action at this time.
0 commit comments