@@ -722,52 +722,53 @@ func (b *blockEnc) encode(org []byte, raw, rawAllLits bool) error {
722
722
println ("Encoded seq" , seq , s , "codes:" , s .llCode , s .mlCode , s .ofCode , "states:" , ll .state , ml .state , of .state , "bits:" , llB , mlB , ofB )
723
723
}
724
724
seq --
725
- if llEnc .maxBits + mlEnc .maxBits + ofEnc .maxBits <= 32 {
726
- // No need to flush (common)
727
- for seq >= 0 {
728
- s = b .sequences [seq ]
729
- wr .flush32 ()
730
- llB , ofB , mlB := llTT [s .llCode ], ofTT [s .ofCode ], mlTT [s .mlCode ]
731
- // tabelog max is 8 for all.
732
- of .encode (ofB )
733
- ml .encode (mlB )
734
- ll .encode (llB )
735
- wr .flush32 ()
736
-
737
- // We checked that all can stay within 32 bits
738
- wr .addBits32NC (s .litLen , llB .outBits )
739
- wr .addBits32NC (s .matchLen , mlB .outBits )
740
- wr .addBits32NC (s .offset , ofB .outBits )
741
-
742
- if debugSequences {
743
- println ("Encoded seq" , seq , s )
744
- }
745
-
746
- seq --
747
- }
748
- } else {
749
- for seq >= 0 {
750
- s = b .sequences [seq ]
751
- wr .flush32 ()
752
- llB , ofB , mlB := llTT [s .llCode ], ofTT [s .ofCode ], mlTT [s .mlCode ]
753
- // tabelog max is below 8 for each.
754
- of .encode (ofB )
755
- ml .encode (mlB )
756
- ll .encode (llB )
757
- wr .flush32 ()
758
-
759
- // ml+ll = max 32 bits total
760
- wr .addBits32NC (s .litLen , llB .outBits )
761
- wr .addBits32NC (s .matchLen , mlB .outBits )
762
- wr .flush32 ()
763
- wr .addBits32NC (s .offset , ofB .outBits )
764
-
765
- if debugSequences {
766
- println ("Encoded seq" , seq , s )
767
- }
768
-
769
- seq --
770
- }
725
+ // Store sequences in reverse...
726
+ for seq >= 0 {
727
+ s = b .sequences [seq ]
728
+
729
+ ofB := ofTT [s .ofCode ]
730
+ wr .flush32 () // tablelog max is below 8 for each, so it will fill max 24 bits.
731
+ //of.encode(ofB)
732
+ nbBitsOut := (uint32 (of .state ) + ofB .deltaNbBits ) >> 16
733
+ dstState := int32 (of .state >> (nbBitsOut & 15 )) + int32 (ofB .deltaFindState )
734
+ wr .addBits16NC (of .state , uint8 (nbBitsOut ))
735
+ of .state = of .stateTable [dstState ]
736
+
737
+ // Accumulate extra bits.
738
+ outBits := ofB .outBits & 31
739
+ extraBits := uint64 (s .offset & bitMask32 [outBits ])
740
+ extraBitsN := outBits
741
+
742
+ mlB := mlTT [s .mlCode ]
743
+ //ml.encode(mlB)
744
+ nbBitsOut = (uint32 (ml .state ) + mlB .deltaNbBits ) >> 16
745
+ dstState = int32 (ml .state >> (nbBitsOut & 15 )) + int32 (mlB .deltaFindState )
746
+ wr .addBits16NC (ml .state , uint8 (nbBitsOut ))
747
+ ml .state = ml .stateTable [dstState ]
748
+
749
+ outBits = mlB .outBits & 31
750
+ extraBits = extraBits << outBits | uint64 (s .matchLen & bitMask32 [outBits ])
751
+ extraBitsN += outBits
752
+
753
+ llB := llTT [s .llCode ]
754
+ //ll.encode(llB)
755
+ nbBitsOut = (uint32 (ll .state ) + llB .deltaNbBits ) >> 16
756
+ dstState = int32 (ll .state >> (nbBitsOut & 15 )) + int32 (llB .deltaFindState )
757
+ wr .addBits16NC (ll .state , uint8 (nbBitsOut ))
758
+ ll .state = ll .stateTable [dstState ]
759
+
760
+ outBits = llB .outBits & 31
761
+ extraBits = extraBits << outBits | uint64 (s .litLen & bitMask32 [outBits ])
762
+ extraBitsN += outBits
763
+
764
+ wr .flush32 ()
765
+ wr .addBits64NC (extraBits , extraBitsN )
766
+
767
+ if debugSequences {
768
+ println ("Encoded seq" , seq , s )
769
+ }
770
+
771
+ seq --
771
772
}
772
773
ml .flush (mlEnc .actualTableLog )
773
774
of .flush (ofEnc .actualTableLog )
@@ -820,7 +821,8 @@ func (b *blockEnc) genCodes() {
820
821
}
821
822
822
823
var llMax , ofMax , mlMax uint8
823
- for i , seq := range b .sequences {
824
+ for i := range b .sequences {
825
+ seq := & b .sequences [i ]
824
826
v := llCode (seq .litLen )
825
827
seq .llCode = v
826
828
llH [v ]++
@@ -844,7 +846,6 @@ func (b *blockEnc) genCodes() {
844
846
panic (fmt .Errorf ("mlMax > maxMatchLengthSymbol (%d), matchlen: %d" , mlMax , seq .matchLen ))
845
847
}
846
848
}
847
- b .sequences [i ] = seq
848
849
}
849
850
maxCount := func (a []uint32 ) int {
850
851
var max uint32
0 commit comments