File tree Expand file tree Collapse file tree 2 files changed +56
-0
lines changed
Microsoft.Toolkit.HighPerformance/Extensions Expand file tree Collapse file tree 2 files changed +56
-0
lines changed Original file line number Diff line number Diff line change @@ -380,5 +380,33 @@ public static int GetDjb2HashCode<T>(this ReadOnlySpan<T> span)
380
380
381
381
return SpanHelper . GetDjb2HashCode ( ref r0 , length ) ;
382
382
}
383
+
384
+ /// <summary>
385
+ /// Copies the contents of a given <see cref="ReadOnlySpan{T}"/> into destination <see cref="RefEnumerable{T}"/> instance.
386
+ /// </summary>
387
+ /// <typeparam name="T">The type of items in the input <see cref="ReadOnlySpan{T}"/> instance.</typeparam>
388
+ /// <param name="span">The input <see cref="ReadOnlySpan{T}"/> instance.</param>
389
+ /// <param name="destination">The <see cref="RefEnumerable{T}"/> instance to copy items into.</param>
390
+ /// <exception cref="ArgumentException">
391
+ /// Thrown when the destination <see cref="RefEnumerable{T}"/> is shorter than the source <see cref="ReadOnlySpan{T}"/>.
392
+ /// </exception>
393
+ [ MethodImpl ( MethodImplOptions . AggressiveInlining ) ]
394
+ public static void CopyTo < T > ( this ReadOnlySpan < T > span , RefEnumerable < T > destination )
395
+ {
396
+ destination . CopyFrom ( span ) ;
397
+ }
398
+
399
+ /// <summary>
400
+ /// Attempts to copy the contents of a given <see cref="ReadOnlySpan{T}"/> into destination <see cref="RefEnumerable{T}"/> instance.
401
+ /// </summary>
402
+ /// <typeparam name="T">The type of items in the input <see cref="ReadOnlySpan{T}"/> instance.</typeparam>
403
+ /// <param name="span">The input <see cref="ReadOnlySpan{T}"/> instance.</param>
404
+ /// <param name="destination">The <see cref="RefEnumerable{T}"/> instance to copy items into.</param>
405
+ /// <returns>Whether or not the operation was successful.</returns>
406
+ [ MethodImpl ( MethodImplOptions . AggressiveInlining ) ]
407
+ public static bool TryCopyTo < T > ( this ReadOnlySpan < T > span , RefEnumerable < T > destination )
408
+ {
409
+ return destination . TryCopyFrom ( span ) ;
410
+ }
383
411
}
384
412
}
Original file line number Diff line number Diff line change @@ -271,6 +271,34 @@ public static int GetDjb2HashCode<T>(this Span<T> span)
271
271
return SpanHelper . GetDjb2HashCode ( ref r0 , length ) ;
272
272
}
273
273
274
+ /// <summary>
275
+ /// Copies the contents of a given <see cref="Span{T}"/> into destination <see cref="RefEnumerable{T}"/> instance.
276
+ /// </summary>
277
+ /// <typeparam name="T">The type of items in the input <see cref="Span{T}"/> instance.</typeparam>
278
+ /// <param name="span">The input <see cref="Span{T}"/> instance.</param>
279
+ /// <param name="destination">The <see cref="RefEnumerable{T}"/> instance to copy items into.</param>
280
+ /// <exception cref="ArgumentException">
281
+ /// Thrown when the destination <see cref="RefEnumerable{T}"/> is shorter than the source <see cref="Span{T}"/>.
282
+ /// </exception>
283
+ [ MethodImpl ( MethodImplOptions . AggressiveInlining ) ]
284
+ public static void CopyTo < T > ( this Span < T > span , RefEnumerable < T > destination )
285
+ {
286
+ destination . CopyFrom ( span ) ;
287
+ }
288
+
289
+ /// <summary>
290
+ /// Attempts to copy the contents of a given <see cref="Span{T}"/> into destination <see cref="RefEnumerable{T}"/> instance.
291
+ /// </summary>
292
+ /// <typeparam name="T">The type of items in the input <see cref="Span{T}"/> instance.</typeparam>
293
+ /// <param name="span">The input <see cref="Span{T}"/> instance.</param>
294
+ /// <param name="destination">The <see cref="RefEnumerable{T}"/> instance to copy items into.</param>
295
+ /// <returns>Whether or not the operation was successful.</returns>
296
+ [ MethodImpl ( MethodImplOptions . AggressiveInlining ) ]
297
+ public static bool TryCopyTo < T > ( this Span < T > span , RefEnumerable < T > destination )
298
+ {
299
+ return destination . TryCopyFrom ( span ) ;
300
+ }
301
+
274
302
/// <summary>
275
303
/// Throws an <see cref="ArgumentOutOfRangeException"/> when the given reference is out of range.
276
304
/// </summary>
You can’t perform that action at this time.
0 commit comments