Skip to content

Commit

Permalink
Micro optimization
Browse files Browse the repository at this point in the history
  • Loading branch information
flanglet committed Jan 25, 2024
1 parent 05439b6 commit 550695f
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
4 changes: 2 additions & 2 deletions v2/entropy/EntropyUtils.go
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ func NormalizeFrequencies(freqs []int, alphabet []int, totalFreq, scale int) (in

if sumScaledFreq != scale {
delta := sumScaledFreq - scale
errThr := freqs[idxMax] >> 4
errThr := freqs[idxMax] >> 4
var inc, absDelta int

if delta < 0 {
Expand All @@ -242,7 +242,7 @@ errThr := freqs[idxMax] >> 4
}

if delta < 0 {
freqs[idxMax] += errThr
freqs[idxMax] += errThr
sumScaledFreq += errThr
} else {
freqs[idxMax] -= errThr
Expand Down
6 changes: 3 additions & 3 deletions v2/entropy/HuffmanCodec.go
Original file line number Diff line number Diff line change
Expand Up @@ -747,9 +747,9 @@ func (this *HuffmanDecoder) Read(block []byte) (int, error) {

for idx < sz-8 {
shift := uint8((56 - bits) & 0xF8)
state = (state << shift) | (binary.BigEndian.Uint64(this.buffer[idx:idx+8]) >> (63 - shift) >> 1) // handle shift = 0
bs := bits + shift - _HUF_MAX_SYMBOL_SIZE_V4
state = (state << shift) | (binary.BigEndian.Uint64(this.buffer[idx:idx+8]) >> 1 >> (63 - shift)) // handle shift = 0
idx += int(shift >> 3)
bs := bits + shift - _HUF_MAX_SYMBOL_SIZE_V4
val0 := this.table[(state>>bs)&_HUF_DECODING_MASK_V4]
bs -= uint8(val0)
val1 := this.table[(state>>bs)&_HUF_DECODING_MASK_V4]
Expand All @@ -758,12 +758,12 @@ func (this *HuffmanDecoder) Read(block []byte) (int, error) {
bs -= uint8(val2)
val3 := this.table[(state>>bs)&_HUF_DECODING_MASK_V4]
bs -= uint8(val3)
bits = bs + _HUF_MAX_SYMBOL_SIZE_V4
block[n+0] = byte(val0 >> 8)
block[n+1] = byte(val1 >> 8)
block[n+2] = byte(val2 >> 8)
block[n+3] = byte(val3 >> 8)
n += 4
bits = bs + _HUF_MAX_SYMBOL_SIZE_V4
}

// Last bytes
Expand Down

0 comments on commit 550695f

Please sign in to comment.