Пример #1
0
        static IMemoryOwner <TSource> ToArray <TList, TSource>(this TList source, int offset, int count, MemoryPool <TSource> pool)
            where TList : notnull, IReadOnlyList <TSource>
        {
            Debug.Assert(pool is object);

            var result = pool.RentSliced(count);

            ReadOnlyListExtensions.Copy <TList, TSource>(source, offset, result.Memory.Span, count);
            return(result);
        }
Пример #2
0
        static TResult[] ToArray <TList, TSource, TResult>(this TList source, NullableSelector <TSource, TResult> selector, int offset, int count)
            where TList : notnull, IReadOnlyList <TSource>
        {
#if NET5_0
            var result = GC.AllocateUninitializedArray <TResult>(count);
#else
            var result = new TResult[count];
#endif
            ReadOnlyListExtensions.Copy(source, offset, result, 0, count, selector);
            return(result);
        }