Skip to content

Commit

Permalink
Remove (unlikely) error branch
Browse files Browse the repository at this point in the history
  • Loading branch information
flanglet committed Aug 25, 2024
1 parent fa9682d commit f08d30f
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions v2/entropy/HuffmanCodec.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,13 +174,25 @@ func (this *HuffmanEncoder) updateFrequencies(freqs []int) (int, error) {
}

if maxCodeLen > _HUF_MAX_SYMBOL_SIZE_V4 {
// Attempt to limit codes max width
if _, err = this.limitCodeLengths(symbols, freqs, sizes[:], ranks[0:count]); err != nil {
return count, err
}
}

if _, err = generateCanonicalCodes(sizes[:], this.codes[:], ranks[0:count], _HUF_MAX_SYMBOL_SIZE_V4); err != nil {
return count, err
if maxCodeLen > _HUF_MAX_SYMBOL_SIZE_V4 {
// Unlikely branch when no codes could be found that fit within _HUF_MAX_SYMBOL_SIZE_V4 width
n := uint16(0)

for i := 0; i < count; i++ {
this.codes[alphabet[i]] = n
sizes[alphabet[i]] = 8
n++
}
} else {
if _, err = generateCanonicalCodes(sizes[:], this.codes[:], ranks[0:count], _HUF_MAX_SYMBOL_SIZE_V4); err != nil {
return count, err
}
}
}

Expand Down

0 comments on commit f08d30f

Please sign in to comment.