@@ -10,7 +10,7 @@ internal class Huffman
1010 {
1111 private static ushort [ ] ? s_decodingTree ;
1212
13- // TODO: this can be constructed from _decodingTable
13+ // HPack static huffman code. see: https://httpwg.org/specs/rfc7541.html#huffman.code
1414 private static readonly ( uint code , int bitLength ) [ ] _encodingTable = new ( uint code , int bitLength ) [ ]
1515 {
1616 ( 0b11111111_11000000_00000000_00000000 , 13 ) ,
@@ -336,7 +336,7 @@ private static ushort[] GenerateDecodingLookupTree()
336336 // +-------------------------------+
337337 // next_code_bits are 'random' bits of next huffman code, so in order for lookup
338338 // 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 ) ;
340340 for ( int suffix = 0 ; suffix < suffixCount ; suffix ++ )
341341 {
342342 if ( octet == 256 )
@@ -365,7 +365,7 @@ private static ushort[] GenerateDecodingLookupTree()
365365 else
366366 {
367367 // 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 ] ;
369369
370370 // Because next_lookup_table_index can not be 0, as 0 is index of root table, default value of array element
371371 // 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)
415415 {
416416 Volatile . Write ( ref s_decodingTree , GenerateDecodingLookupTree ( ) ) ;
417417 }
418+ ushort [ ] decodingTree = s_decodingTree ;
418419
419420 int lookupTableIndex = 0 ;
420421 int lookupIndex ;
@@ -440,7 +441,7 @@ public static int Decode(ReadOnlySpan<byte> src, ref byte[] dstArray)
440441 {
441442 lookupIndex = ( byte ) ( acc >> ( bitsInAcc - 8 ) ) ;
442443
443- var lookupValue = s_decodingTree [ ( lookupTableIndex << 8 ) + lookupIndex ] ;
444+ ushort lookupValue = decodingTree [ ( lookupTableIndex << 8 ) + lookupIndex ] ;
444445
445446 if ( lookupValue >= 0x80_00 )
446447 {
@@ -500,7 +501,7 @@ public static int Decode(ReadOnlySpan<byte> src, ref byte[] dstArray)
500501 // Lookup index has to be 8 bits aligned to MSB
501502 lookupIndex = ( byte ) ( acc << ( 8 - bitsInAcc ) ) ;
502503
503- var lookupValue = s_decodingTree [ ( lookupTableIndex << 8 ) + lookupIndex ] ;
504+ ushort lookupValue = decodingTree [ ( lookupTableIndex << 8 ) + lookupIndex ] ;
504505
505506 if ( lookupValue >= 0x80_00 )
506507 {
0 commit comments