-
Notifications
You must be signed in to change notification settings - Fork 485
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
use ArrayPool for stream buffer use stackalloc for methods on file decompression code path
- Loading branch information
root
committed
Mar 14, 2024
1 parent
4afc7ae
commit d2d4755
Showing
6 changed files
with
74 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
using System.Buffers; | ||
|
||
namespace SharpCompress; | ||
|
||
internal static class BufferPool | ||
{ | ||
/// <summary> | ||
/// Gets a buffer. | ||
/// </summary> | ||
/// <param name="bufferSize">Size of the buffer.</param> | ||
/// <returns></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 the buffer. | ||
/// </summary> | ||
/// <param name="buffer">The buffer.</param> | ||
public static void Return(byte[] buffer) | ||
{ | ||
#if NETCOREAPP || NETSTANDARD2_1_OR_GREATER | ||
ArrayPool<byte>.Shared.Return(buffer); | ||
#else | ||
// no-op | ||
#endif | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters