Skip to content

Commit

Permalink
Code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
flanglet committed Nov 5, 2024
1 parent df808a4 commit f9efca8
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 14 deletions.
6 changes: 3 additions & 3 deletions v2/entropy/ANSRangeCodec.go
Original file line number Diff line number Diff line change
Expand Up @@ -731,10 +731,10 @@ func (this *ANSRangeDecoder) Read(block []byte) (int, error) {
for startChunk < end {
endChunk := min(startChunk+sizeChunk, end)
sizeChunk = endChunk - startChunk
alphabetSize, err := this.decodeHeader(this.freqs, alphabet[:])
alphabetSize, errH := this.decodeHeader(this.freqs, alphabet[:])

if err != nil || alphabetSize == 0 {
return startChunk, err
if errH != nil || alphabetSize == 0 {
return startChunk, errH
}

if this.order == 0 && alphabetSize == 1 {
Expand Down
2 changes: 1 addition & 1 deletion v2/io/CompressedStream.go
Original file line number Diff line number Diff line change
Expand Up @@ -842,7 +842,7 @@ func (this *encodingTask) encode(res *encodingTaskResult) {

func notifyListeners(listeners []kanzi.Listener, evt *kanzi.Event) {
defer func() {
//nolint
// nolint:staticcheck
if r := recover(); r != nil {
//lint:ignore SA9003
// Ignore panics in block listeners
Expand Down
11 changes: 5 additions & 6 deletions v2/transform/TextCodec.go
Original file line number Diff line number Diff line change
Expand Up @@ -187,8 +187,7 @@ func computeTextStats(block []byte, freqs0 []int, strict bool) byte {
return _TC_MASK_NOT_TEXT
}

var freqs [256][256]int
freqs1 := freqs[0:256]
freqs1 := make([][256]int, 256)
count := len(block)
end4 := count & -4
prv := byte(0)
Expand Down Expand Up @@ -236,16 +235,16 @@ func computeTextStats(block []byte, freqs0 []int, strict bool) byte {
notText = true
} else {
if strict == true {
notText = (nbTextChars < (count >> 2)) || (freqs0[0] >= count/100) || ((nbASCII / 95) < (count / 100))
notText = (nbTextChars < (count / 4)) || (freqs0[0] >= count/100) || ((nbASCII / 95) < (count / 100))
} else {
notText = (nbTextChars < (count >> 1)) || (freqs0[32] < count/50)
notText = (nbTextChars < (count / 2)) || (freqs0[32] < count/50)
}
}

res := byte(0)

if notText == true {
return res | detectTextType(freqs0, freqs[:], count)
return res | detectTextType(freqs0, freqs1[:], count)
}

if nbBinChars <= count-count/10 {
Expand All @@ -255,7 +254,7 @@ func computeTextStats(block []byte, freqs0 []int, strict bool) byte {
// Getting this flag wrong results in a very small compression speed degradation.
f1 := freqs0['<']
f2 := freqs0['>']
f3 := freqs['&']['a'] + freqs['&']['g'] + freqs['&']['l'] + freqs['&']['q']
f3 := freqs1['&']['a'] + freqs1['&']['g'] + freqs1['&']['l'] + freqs1['&']['q']
minFreq := (count - nbBinChars) >> 9

if minFreq < 2 {
Expand Down
6 changes: 2 additions & 4 deletions v2/transform/UTFCodec.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,11 +163,9 @@ func (this *UTFCodec) Forward(src, dst []byte) (uint, uint, error) {
res := s != 0
// Validation of longer sequences
// Third byte in [0x80..0xBF]
res = res && ((s != 3) || ((src[i+2] >= 0x80) && (src[i+2] <= 0xBF)))
// Combine third and fourth bytes
v := (uint16(src[i+2]) << 8) | uint16(src[i+3])
res = res && ((s != 3) || ((src[i+2] & 0xC0) == 0x80))
// Third and fourth bytes in [0x80..0xBF]
res = res && ((s != 4) || (v&0xC0C0) == 0x8080)
res = res && ((s != 4) || ((((uint16(src[i+2]) << 8) | uint16(src[i+3])) & 0xC0C0) == 0x8080))

if aliasMap[val] == 0 {
symb[n].sym = int32(val)
Expand Down

0 comments on commit f9efca8

Please sign in to comment.