BufferUtils
using System.Runtime.CompilerServices;
namespace Newtonsoft.Json.Utilities
{
    [System.Runtime.CompilerServices.NullableContext(2)]
    [System.Runtime.CompilerServices.Nullable(0)]
    internal static class BufferUtils
    {
        [System.Runtime.CompilerServices.NullableContext(1)]
        public static char[] RentBuffer([System.Runtime.CompilerServices.Nullable(2)] IArrayPool<char> bufferPool, int minSize)
        {
            if (bufferPool == null)
                return new char[minSize];
            return bufferPool.Rent(minSize);
        }
        public static void ReturnBuffer(IArrayPool<char> bufferPool, char[] buffer)
        {
            bufferPool?.Return(buffer);
        }
        [return: System.Runtime.CompilerServices.Nullable(1)]
        public static char[] EnsureBufferSize(IArrayPool<char> bufferPool, int size, char[] buffer)
        {
            if (bufferPool == null)
                return new char[size];
            if (buffer != null)
                bufferPool.Return(buffer);
            return bufferPool.Rent(size);
        }
    }
}