@@ -40,7 +40,7 @@ internal unsafe struct PdfJsHuffmanTable
4040 /// <param name="memoryManager">The <see cref="MemoryManager"/> to use for buffer allocations.</param>
4141 /// <param name="lengths">The code lengths</param>
4242 /// <param name="values">The huffman values</param>
43- public PdfJsHuffmanTable ( MemoryManager memoryManager , byte [ ] lengths , byte [ ] values )
43+ public PdfJsHuffmanTable ( MemoryManager memoryManager , ReadOnlySpan < byte > lengths , ReadOnlySpan < byte > values )
4444 {
4545 const int length = 257 ;
4646 using ( IBuffer < short > huffsize = memoryManager . Allocate < short > ( length ) )
@@ -57,10 +57,9 @@ public PdfJsHuffmanTable(MemoryManager memoryManager, byte[] lengths, byte[] val
5757
5858 fixed ( byte * huffValRef = this . HuffVal . Data )
5959 {
60- for ( int i = 0 ; i < values . Length ; i ++ )
61- {
62- huffValRef [ i ] = values [ i ] ;
63- }
60+ var huffValSpan = new Span < byte > ( huffValRef , 256 ) ;
61+
62+ values . CopyTo ( huffValSpan ) ;
6463 }
6564 }
6665
@@ -69,7 +68,7 @@ public PdfJsHuffmanTable(MemoryManager memoryManager, byte[] lengths, byte[] val
6968 /// </summary>
7069 /// <param name="lengths">The code lengths</param>
7170 /// <param name="huffsizeRef">The huffman size span ref</param>
72- private static void GenerateSizeTable ( byte [ ] lengths , ref short huffsizeRef )
71+ private static void GenerateSizeTable ( ReadOnlySpan < byte > lengths , ref short huffsizeRef )
7372 {
7473 short index = 0 ;
7574 for ( short l = 1 ; l <= 16 ; l ++ )
@@ -115,7 +114,7 @@ private static void GenerateCodeTable(ref short huffsizeRef, ref short huffcodeR
115114 /// </summary>
116115 /// <param name="lengths">The code lengths</param>
117116 /// <param name="huffcodeRef">The huffman code span ref</param>
118- private void GenerateDecoderTables ( byte [ ] lengths , ref short huffcodeRef )
117+ private void GenerateDecoderTables ( ReadOnlySpan < byte > lengths , ref short huffcodeRef )
119118 {
120119 fixed ( short * valOffsetRef = this . ValOffset . Data )
121120 fixed ( long * maxcodeRef = this . MaxCode . Data )
@@ -147,18 +146,17 @@ private void GenerateDecoderTables(byte[] lengths, ref short huffcodeRef)
147146 /// <param name="lengths">The code lengths</param>
148147 /// <param name="huffval">The huffman value array</param>
149148 /// <param name="huffcodeRef">The huffman code span ref</param>
150- private void GenerateLookaheadTables ( byte [ ] lengths , byte [ ] huffval , ref short huffcodeRef )
149+ private void GenerateLookaheadTables ( ReadOnlySpan < byte > lengths , ReadOnlySpan < byte > huffval , ref short huffcodeRef )
151150 {
152151 // TODO: This generation code matches the libJpeg code but the lookahead table is not actually used yet.
153152 // To use it we need to implement fast lookup path in PdfJsScanDecoder.DecodeHuffman
154153 // This should yield much faster scan decoding as usually, more than 95% of the Huffman codes
155154 // will be 8 or fewer bits long and can be handled without looping.
156155 fixed ( short * lookaheadRef = this . Lookahead . Data )
157156 {
158- for ( int i = 0 ; i < 256 ; i ++ )
159- {
160- lookaheadRef [ i ] = 2034 ; // 9 << 8;
161- }
157+ var lookaheadSpan = new Span < short > ( lookaheadRef , 256 ) ;
158+
159+ lookaheadSpan . Fill ( 2034 ) ; // 9 << 8;
162160
163161 int p = 0 ;
164162 for ( int l = 1 ; l <= 8 ; l ++ )
0 commit comments