AngleSharp by AngleSharp

<PackageReference Include="AngleSharp" Version="1.4.0" />

 ArrayPoolExtensions

static class ArrayPoolExtensions
using System; using System.Buffers; using System.Runtime.CompilerServices; namespace AngleSharp.Common { [System.Runtime.CompilerServices.NullableContext(1)] [System.Runtime.CompilerServices.Nullable(0)] internal static class ArrayPoolExtensions { [System.Runtime.CompilerServices.Nullable(0)] internal readonly struct Lease<[System.Runtime.CompilerServices.Nullable(2)] T> : IDisposable { private readonly ArrayPool<T> _owner; private readonly T[] _data; private readonly int _requestedLength; public int RequestedLength => _requestedLength; public T[] Data => _data; [System.Runtime.CompilerServices.Nullable(new byte[] { 0, 1 })] public Span<T> Span { [return: System.Runtime.CompilerServices.Nullable(new byte[] { 0, 1 })] get { return MemoryExtensions.AsSpan<T>(Data, 0, RequestedLength); } } [System.Runtime.CompilerServices.Nullable(new byte[] { 0, 1 })] public Memory<T> Memory { [return: System.Runtime.CompilerServices.Nullable(new byte[] { 0, 1 })] get { return MemoryExtensions.AsMemory<T>(Data, 0, RequestedLength); } } public Lease(ArrayPool<T> owner, T[] data, int requestedLength) { _owner = owner; _data = data; _requestedLength = requestedLength; } public void Dispose() { _owner.Return(_data, false); } } [return: System.Runtime.CompilerServices.Nullable(new byte[] { 0, 1 })] internal static Lease<T> Borrow<[System.Runtime.CompilerServices.Nullable(2)] T>(this ArrayPool<T> pool, int length) { T[] data = ArrayPool<T>.Shared.Rent(length); return new Lease<T>(ArrayPool<T>.Shared, data, length); } } }