lampac/Shared/Engine/Pools/NewtonsoftCharArrayPool.cs
lampac-talks f843f04fd4 chore: initial commit 154.3
Signed-off-by: lampac-talks <lampac-talks@users.noreply.github.com>
2026-01-30 16:23:09 +03:00

25 lines
692 B
C#

using Newtonsoft.Json;
using System.Buffers;
namespace Shared.Engine.Utilities
{
public static class NewtonsoftPool
{
public static readonly IArrayPool<char> Array = new NewtonsoftCharArrayPool();
}
public class NewtonsoftCharArrayPool : IArrayPool<char>
{
private readonly ArrayPool<char> _pool;
public NewtonsoftCharArrayPool(ArrayPool<char> pool = null, bool clearOnReturn = false)
{
_pool = pool ?? ArrayPool<char>.Shared;
}
public char[] Rent(int minimumLength) => _pool.Rent(PoolInvk.Rent(minimumLength));
public void Return(char[] array) => _pool.Return(array, clearArray: false);
}
}