From a649c25a916b2d4331f91c832c5ab4df3a730cc7 Mon Sep 17 00:00:00 2001 From: Jason Nelson Date: Fri, 31 Jul 2020 16:58:21 -0700 Subject: [PATCH] Eliminate two allocations in HuffmanTree --- src/SharpCompress/Compressors/Deflate64/HuffmanTree.cs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/SharpCompress/Compressors/Deflate64/HuffmanTree.cs b/src/SharpCompress/Compressors/Deflate64/HuffmanTree.cs index 8741930c..017c1cb9 100644 --- a/src/SharpCompress/Compressors/Deflate64/HuffmanTree.cs +++ b/src/SharpCompress/Compressors/Deflate64/HuffmanTree.cs @@ -2,6 +2,7 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. +using System; using System.Diagnostics; using System.IO; @@ -118,14 +119,14 @@ namespace SharpCompress.Compressors.Deflate64 // This algorithm is described in standard RFC 1951 private uint[] CalculateHuffmanCode() { - uint[] bitLengthCount = new uint[17]; + Span bitLengthCount = stackalloc uint[17]; foreach (int codeLength in _codeLengthArray) { bitLengthCount[codeLength]++; } bitLengthCount[0] = 0; // clear count for length 0 - uint[] nextCode = new uint[17]; + Span nextCode = stackalloc uint[17]; uint tempCode = 0; for (int bits = 1; bits <= 16; bits++) {