mirror of
https://github.com/adamhathcock/sharpcompress.git
synced 2026-07-21 16:35:23 +00:00
use ArrayPool for stream buffer use stackalloc for methods on file decompression code path
34 lines
784 B
C#
34 lines
784 B
C#
using System.Buffers;
|
|
|
|
namespace SharpCompress;
|
|
|
|
internal static class BufferPool
|
|
{
|
|
/// <summary>
|
|
/// gets a buffer from the pool
|
|
/// </summary>
|
|
/// <param name="bufferSize">size of the buffer</param>
|
|
/// <returns>the buffer</returns>
|
|
public static byte[] Rent(int bufferSize)
|
|
{
|
|
#if NETCOREAPP || NETSTANDARD2_1_OR_GREATER
|
|
return ArrayPool<byte>.Shared.Rent(bufferSize);
|
|
#else
|
|
return new byte[bufferSize];
|
|
#endif
|
|
}
|
|
|
|
/// <summary>
|
|
/// returns a buffer to the pool
|
|
/// </summary>
|
|
/// <param name="buffer">the buffer to return</param>
|
|
public static void Return(byte[] buffer)
|
|
{
|
|
#if NETCOREAPP || NETSTANDARD2_1_OR_GREATER
|
|
ArrayPool<byte>.Shared.Return(buffer);
|
|
#else
|
|
// no-op
|
|
#endif
|
|
}
|
|
}
|