setPrev will update the previous encoders to the actually used ones and make sure a fresh one is in the main slot.
(ll, ml, of *fseEncoder)
| 19 | // setPrev will update the previous encoders to the actually used ones |
| 20 | // and make sure a fresh one is in the main slot. |
| 21 | func (s *seqCoders) setPrev(ll, ml, of *fseEncoder) { |
| 22 | compareSwap := func(used *fseEncoder, current, prev **fseEncoder) { |
| 23 | // We used the new one, more current to history and reuse the previous history |
| 24 | if *current == used { |
| 25 | *prev, *current = *current, *prev |
| 26 | c := *current |
| 27 | p := *prev |
| 28 | c.reUsed = false |
| 29 | p.reUsed = true |
| 30 | return |
| 31 | } |
| 32 | if used == *prev { |
| 33 | return |
| 34 | } |
| 35 | // Ensure we cannot reuse by accident |
| 36 | prevEnc := *prev |
| 37 | prevEnc.symbolLen = 0 |
| 38 | } |
| 39 | compareSwap(ll, &s.llEnc, &s.llPrev) |
| 40 | compareSwap(ml, &s.mlEnc, &s.mlPrev) |
| 41 | compareSwap(of, &s.ofEnc, &s.ofPrev) |
| 42 | } |
| 43 | |
| 44 | func highBit(val uint32) (n uint32) { |
| 45 | return uint32(bits.Len32(val) - 1) |
no outgoing calls
no test coverage detected