@@ -166,7 +166,7 @@ public readonly void Clear()
166
166
/// </summary>
167
167
/// <param name="destination">The destination <see cref="Span{T}"/> instance.</param>
168
168
/// <exception cref="ArgumentException">
169
- /// Thrown when <paramref name="destination" /> is shorter than the source <see cref="RefEnumerable{T}"/> instance.
169
+ /// Thrown when <paramref name="destination"/> is shorter than the source <see cref="RefEnumerable{T}"/> instance.
170
170
/// </exception>
171
171
public readonly void CopyTo ( Span < T > destination )
172
172
{
@@ -213,7 +213,7 @@ public readonly bool TryCopyTo(Span<T> destination)
213
213
int length = this . length ;
214
214
#endif
215
215
216
- if ( destination . Length >= length / this . step )
216
+ if ( destination . Length >= length )
217
217
{
218
218
CopyTo ( destination ) ;
219
219
@@ -223,6 +223,70 @@ public readonly bool TryCopyTo(Span<T> destination)
223
223
return false ;
224
224
}
225
225
226
+ /// <summary>
227
+ /// Copies the contents of a source <see cref="ReadOnlySpan{T}"/> into the current <see cref="RefEnumerable{T}"/> instance.
228
+ /// </summary>
229
+ /// <param name="source">The source <see cref="ReadOnlySpan{T}"/> instance.</param>
230
+ /// <exception cref="ArgumentException">
231
+ /// Thrown when the current <see cref="RefEnumerable{T}"/> is shorter than the source <see cref="ReadOnlySpan{T}"/> instance.
232
+ /// </exception>
233
+ internal readonly void CopyFrom ( ReadOnlySpan < T > source )
234
+ {
235
+ #if SPAN_RUNTIME_SUPPORT
236
+ if ( this . step == 1 )
237
+ {
238
+ source . CopyTo ( this . span ) ;
239
+
240
+ return ;
241
+ }
242
+
243
+ ref T destinationRef = ref this . span . DangerousGetReference ( ) ;
244
+ int destinationLength = this . span . Length ;
245
+ #else
246
+ ref T destinationRef = ref RuntimeHelpers . GetObjectDataAtOffsetOrPointerReference < T > ( this . instance , this . offset ) ;
247
+ int destinationLength = this . length ;
248
+ #endif
249
+ ref T sourceRef = ref source . DangerousGetReference ( ) ;
250
+ int sourceLength = source . Length ;
251
+
252
+ if ( ( uint ) destinationLength < ( uint ) sourceLength )
253
+ {
254
+ ThrowArgumentExceptionForDestinationTooShort ( ) ;
255
+ }
256
+
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
+ }
265
+ }
266
+
267
+ /// <summary>
268
+ /// Attempts to copy the source <see cref="ReadOnlySpan{T}"/> into the current <see cref="RefEnumerable{T}"/> instance.
269
+ /// </summary>
270
+ /// <param name="source">The source <see cref="ReadOnlySpan{T}"/> instance.</param>
271
+ /// <returns>Whether or not the operation was successful.</returns>
272
+ public readonly bool TryCopyFrom ( ReadOnlySpan < T > source )
273
+ {
274
+ #if SPAN_RUNTIME_SUPPORT
275
+ int length = this . span . Length ;
276
+ #else
277
+ int length = this . length ;
278
+ #endif
279
+
280
+ if ( length >= source . Length )
281
+ {
282
+ CopyFrom ( source ) ;
283
+
284
+ return true ;
285
+ }
286
+
287
+ return false ;
288
+ }
289
+
226
290
/// <summary>
227
291
/// Fills the elements of this <see cref="RefEnumerable{T}"/> with a specified value.
228
292
/// </summary>
0 commit comments