File tree 3 files changed +22
-14
lines changed
3 files changed +22
-14
lines changed Original file line number Diff line number Diff line change @@ -89,8 +89,8 @@ Consider using `ThreadStatic` or pool of compressors for bulk processing.
89
89
* ` GetCompressBound ` returns required destination buffer size for source data of size ` size ` .
90
90
91
91
``` c#
92
- static int GetCompressBound (int size )
93
- static ulong GetCompressBoundLong (ulong size )
92
+ static int GetCompressBound (int size );
93
+ static ulong GetCompressBoundLong (ulong size );
94
94
```
95
95
96
96
### CompressionStream class
Original file line number Diff line number Diff line change 1
1
using System ;
2
+ using System . Buffers ;
2
3
using size_t = System . UIntPtr ;
3
4
4
5
namespace ZstdNet
@@ -48,15 +49,20 @@ public byte[] Wrap(ReadOnlySpan<byte> src)
48
49
{
49
50
//NOTE: Wrap tries its best, but if src is uncompressible and the size is too large, ZSTD_error_dstSize_tooSmall will be thrown
50
51
var dstCapacity = Math . Min ( Consts . MaxByteArrayLength , GetCompressBoundLong ( ( ulong ) src . Length ) ) ;
51
- var dst = new byte [ dstCapacity ] ;
52
-
53
- var dstSize = Wrap ( src , new Span < byte > ( dst ) ) ;
54
- if ( dstCapacity == ( ulong ) dstSize )
55
- return dst ;
56
-
57
- var result = new byte [ dstSize ] ;
58
- Array . Copy ( dst , result , dstSize ) ;
59
- return result ;
52
+ var dst = ArrayPool < byte > . Shared . Rent ( ( int ) dstCapacity ) ;
53
+
54
+ try
55
+ {
56
+ var dstSize = Wrap ( src , new Span < byte > ( dst ) ) ;
57
+
58
+ var result = new byte [ dstSize ] ;
59
+ Array . Copy ( dst , result , dstSize ) ;
60
+ return result ;
61
+ }
62
+ finally
63
+ {
64
+ ArrayPool < byte > . Shared . Return ( dst ) ;
65
+ }
60
66
}
61
67
62
68
public static int GetCompressBound ( int size )
Original file line number Diff line number Diff line change 1
1
version : 1.0.{build}
2
2
image : Visual Studio 2019
3
+ install :
4
+ - appveyor DownloadFile https://dist.nuget.org/win-x86-commandline/v5.8.0/nuget.exe
3
5
before_build :
4
- - cmd : nuget restore
6
+ - nuget restore
5
7
build :
6
8
verbosity : minimal
7
- cache :
8
- - packages -> **\packages.config
9
+ # cache:
10
+ # - packages -> **\packages.config
You can’t perform that action at this time.
0 commit comments