Merge pull request #37 from vanita5/master

Replace unnecessary mod17 function with builtin mod
This commit is contained in:
John Starks
2017-01-12 16:12:40 -08:00
committed by GitHub
+2 -10
View File
@@ -256,14 +256,6 @@ func (f *decompressor) getCode(h *huffman) uint16 {
return 0 return 0
} }
// mod17 computes the value mod 17.
func mod17(b byte) byte {
for b >= 17 {
b -= 17
}
return b
}
// readTree updates the huffman tree path lengths in lens by // readTree updates the huffman tree path lengths in lens by
// reading and decoding lengths from the byte stream. lens // reading and decoding lengths from the byte stream. lens
// should be prepopulated with the previous block's tree's path // should be prepopulated with the previous block's tree's path
@@ -288,7 +280,7 @@ func (f *decompressor) readTree(lens []byte) error {
} }
switch { switch {
case c <= 16: // length is delta from previous length case c <= 16: // length is delta from previous length
lens[i] = mod17(lens[i] + 17 - c) lens[i] = (lens[i] + 17 - c) % 17
i++ i++
case c == 17: // next n + 4 lengths are zero case c == 17: // next n + 4 lengths are zero
zeroes := int(f.getBits(4)) + 4 zeroes := int(f.getBits(4)) + 4
@@ -317,7 +309,7 @@ func (f *decompressor) readTree(lens []byte) error {
if c > 16 { if c > 16 {
return errCorrupt return errCorrupt
} }
l := mod17(lens[i] + 17 - c) l := (lens[i] + 17 - c) % 17
for j := 0; j < same; j++ { for j := 0; j < same; j++ {
lens[i+j] = l lens[i+j] = l
} }