Skip to content

Commit

Permalink
perf use decompressBuffer (#2030)
Browse files Browse the repository at this point in the history
  • Loading branch information
nkast authored Nov 15, 2024
1 parent 148b9d9 commit 8e0ce4b
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/Xna.Framework.Content/Content/ContentManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,7 @@ private ContentReader GetContentReaderFromXnb(string originalAssetName, Stream s
uint compressedFileSize = xnbReader.ReadUInt32();

Stream decompressedStream = null;
byte[] decompressBuffer = null;
if (isCompressed)
{
// Decompress the xnb
Expand Down Expand Up @@ -277,7 +278,8 @@ private ContentReader GetContentReaderFromXnb(string originalAssetName, Stream s
case 0x03: // Brotli
{
#if NET6_0_OR_GREATER
decompressedStream = new MemoryStream();
decompressBuffer = ContentBufferPool.Current.Get((int)decompressedDataSize);
decompressedStream = new MemoryStream(decompressBuffer);
using (var brotliStream = new System.IO.Compression.BrotliStream(stream, System.IO.Compression.CompressionMode.Decompress, true
))
{
Expand Down Expand Up @@ -320,7 +322,10 @@ private ContentReader GetContentReaderFromXnb(string originalAssetName, Stream s

ContentReader reader = new ContentReader(this, decompressedStream,
originalAssetName, version, compressedFileSize, recordDisposableObject);


if (decompressBuffer != null)
ContentBufferPool.Current.Return(decompressBuffer);

return reader;
}

Expand Down

0 comments on commit 8e0ce4b

Please sign in to comment.