@@ -10,7 +10,7 @@ internal class Huffman
10
10
{
11
11
private static ushort [ ] ? s_decodingTree ;
12
12
13
- // TODO: this can be constructed from _decodingTable
13
+ // HPack static huffman code. see: https://httpwg.org/specs/rfc7541.html#huffman.code
14
14
private static readonly ( uint code , int bitLength ) [ ] _encodingTable = new ( uint code , int bitLength ) [ ]
15
15
{
16
16
( 0b11111111_11000000_00000000_00000000 , 13 ) ,
@@ -336,7 +336,7 @@ private static ushort[] GenerateDecodingLookupTree()
336
336
// +-------------------------------+
337
337
// next_code_bits are 'random' bits of next huffman code, so in order for lookup
338
338
// to work, lookup value has to be stored for all 4 unused bits, in this case for suffix 0..15
339
- var suffixCount = 1 << ( 8 - bitsLeft ) ;
339
+ int suffixCount = 1 << ( 8 - bitsLeft ) ;
340
340
for ( int suffix = 0 ; suffix < suffixCount ; suffix ++ )
341
341
{
342
342
if ( octet == 256 )
@@ -365,7 +365,7 @@ private static ushort[] GenerateDecodingLookupTree()
365
365
else
366
366
{
367
367
// More than 8 bits left in huffman code means that we need to traverse to another lookup table for next 8 bits
368
- var lookupValue = lut [ ( lookupTableIndex << 8 ) + indexInLookupTable ] ;
368
+ ushort lookupValue = lut [ ( lookupTableIndex << 8 ) + indexInLookupTable ] ;
369
369
370
370
// Because next_lookup_table_index can not be 0, as 0 is index of root table, default value of array element
371
371
// means that we have not initialized it yet => lookup table MUST be allocated and its index assigned to that lookup value
@@ -415,6 +415,7 @@ public static int Decode(ReadOnlySpan<byte> src, ref byte[] dstArray)
415
415
{
416
416
Volatile . Write ( ref s_decodingTree , GenerateDecodingLookupTree ( ) ) ;
417
417
}
418
+ ushort [ ] decodingTree = s_decodingTree ;
418
419
419
420
int lookupTableIndex = 0 ;
420
421
int lookupIndex ;
@@ -440,7 +441,7 @@ public static int Decode(ReadOnlySpan<byte> src, ref byte[] dstArray)
440
441
{
441
442
lookupIndex = ( byte ) ( acc >> ( bitsInAcc - 8 ) ) ;
442
443
443
- var lookupValue = s_decodingTree [ ( lookupTableIndex << 8 ) + lookupIndex ] ;
444
+ ushort lookupValue = decodingTree [ ( lookupTableIndex << 8 ) + lookupIndex ] ;
444
445
445
446
if ( lookupValue >= 0x80_00 )
446
447
{
@@ -500,7 +501,7 @@ public static int Decode(ReadOnlySpan<byte> src, ref byte[] dstArray)
500
501
// Lookup index has to be 8 bits aligned to MSB
501
502
lookupIndex = ( byte ) ( acc << ( 8 - bitsInAcc ) ) ;
502
503
503
- var lookupValue = s_decodingTree [ ( lookupTableIndex << 8 ) + lookupIndex ] ;
504
+ ushort lookupValue = decodingTree [ ( lookupTableIndex << 8 ) + lookupIndex ] ;
504
505
505
506
if ( lookupValue >= 0x80_00 )
506
507
{
0 commit comments