From 55a2bb3c301f05eb8fc1a24b19f0c0efc4210061 Mon Sep 17 00:00:00 2001 From: vanita5 Date: Mon, 9 Jan 2017 13:35:03 +0100 Subject: [PATCH] replace unnecessary mod17 function with builtin mod, see #37 and #38 --- wim/lzx/lzx.go | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/wim/lzx/lzx.go b/wim/lzx/lzx.go index 73f8336..4deb0df 100644 --- a/wim/lzx/lzx.go +++ b/wim/lzx/lzx.go @@ -256,14 +256,6 @@ func (f *decompressor) getCode(h *huffman) uint16 { 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 // reading and decoding lengths from the byte stream. lens // should be prepopulated with the previous block's tree's path @@ -288,7 +280,7 @@ func (f *decompressor) readTree(lens []byte) error { } switch { case c <= 16: // length is delta from previous length - lens[i] = mod17(lens[i] + 17 - c) + lens[i] = (lens[i] + 17 - c) % 17 i++ case c == 17: // next n + 4 lengths are zero zeroes := int(f.getBits(4)) + 4 @@ -317,7 +309,7 @@ func (f *decompressor) readTree(lens []byte) error { if c > 16 { return errCorrupt } - l := mod17(lens[i] + 17 - c) + l := (lens[i] + 17 - c) % 17 for j := 0; j < same; j++ { lens[i+j] = l }