diff --git a/flate/deflate.go b/flate/deflate.go index 82882961a0..5faea0b2b3 100644 --- a/flate/deflate.go +++ b/flate/deflate.go @@ -90,9 +90,8 @@ type advancedState struct { ii uint16 // position of last match, intended to overflow to reset. // input window: unprocessed data is window[index:windowEnd] - index int - estBitsPerByte int - hashMatch [maxMatchLength + minMatchLength]uint32 + index int + hashMatch [maxMatchLength + minMatchLength]uint32 // Input hash chains // hashHead[hashValue] contains the largest inputIndex with the specified hash value diff --git a/flate/huffman_bit_writer.go b/flate/huffman_bit_writer.go index 89a5dd89f9..f70594c34e 100644 --- a/flate/huffman_bit_writer.go +++ b/flate/huffman_bit_writer.go @@ -34,11 +34,6 @@ const ( // Should preferably be a multiple of 6, since // we accumulate 6 bytes between writes to the buffer. bufferFlushSize = 246 - - // bufferSize is the actual output byte buffer size. - // It must have additional headroom for a flush - // which can contain up to 8 bytes. - bufferSize = bufferFlushSize + 8 ) // Minimum length code that emits bits. diff --git a/flate/huffman_sortByFreq.go b/flate/huffman_sortByFreq.go index 2077802990..6c05ba8c1c 100644 --- a/flate/huffman_sortByFreq.go +++ b/flate/huffman_sortByFreq.go @@ -42,25 +42,6 @@ func quickSortByFreq(data []literalNode, a, b, maxDepth int) { } } -// siftDownByFreq implements the heap property on data[lo, hi). -// first is an offset into the array where the root of the heap lies. -func siftDownByFreq(data []literalNode, lo, hi, first int) { - root := lo - for { - child := 2*root + 1 - if child >= hi { - break - } - if child+1 < hi && (data[first+child].freq == data[first+child+1].freq && data[first+child].literal < data[first+child+1].literal || data[first+child].freq < data[first+child+1].freq) { - child++ - } - if data[first+root].freq == data[first+child].freq && data[first+root].literal > data[first+child].literal || data[first+root].freq > data[first+child].freq { - return - } - data[first+root], data[first+child] = data[first+child], data[first+root] - root = child - } -} func doPivotByFreq(data []literalNode, lo, hi int) (midlo, midhi int) { m := int(uint(lo+hi) >> 1) // Written like this to avoid integer overflow. if hi-lo > 40 { diff --git a/huff0/bitwriter.go b/huff0/bitwriter.go index aed2347ced..b4d7164e3f 100644 --- a/huff0/bitwriter.go +++ b/huff0/bitwriter.go @@ -13,14 +13,6 @@ type bitWriter struct { out []byte } -// bitMask16 is bitmasks. Has extra to avoid bounds check. -var bitMask16 = [32]uint16{ - 0, 1, 3, 7, 0xF, 0x1F, - 0x3F, 0x7F, 0xFF, 0x1FF, 0x3FF, 0x7FF, - 0xFFF, 0x1FFF, 0x3FFF, 0x7FFF, 0xFFFF, 0xFFFF, - 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, - 0xFFFF, 0xFFFF} /* up to 16 bits */ - // addBits16Clean will add up to 16 bits. value may not contain more set bits than indicated. // It will not check if there is space for them, so the caller must ensure that it has flushed recently. func (b *bitWriter) addBits16Clean(value uint16, bits uint8) { diff --git a/huff0/decompress.go b/huff0/decompress.go index 3c0b398c72..54bd08b25c 100644 --- a/huff0/decompress.go +++ b/huff0/decompress.go @@ -253,7 +253,7 @@ func (d *Decoder) decompress1X8Bit(dst, src []byte) ([]byte, error) { switch d.actualTableLog { case 8: - const shift = 8 - 8 + const shift = 0 for br.off >= 4 { br.fillFast() v := dt[uint8(br.value>>(56+shift))] diff --git a/internal/snapref/encode_other.go b/internal/snapref/encode_other.go index 05db94d39a..2aa6a95a02 100644 --- a/internal/snapref/encode_other.go +++ b/internal/snapref/encode_other.go @@ -87,18 +87,6 @@ func emitCopy(dst []byte, offset, length int) int { return i + 2 } -// extendMatch returns the largest k such that k <= len(src) and that -// src[i:i+k-j] and src[j:k] have the same contents. -// -// It assumes that: -// -// 0 <= i && i < j && j <= len(src) -func extendMatch(src []byte, i, j int) int { - for ; j < len(src) && src[i] == src[j]; i, j = i+1, j+1 { - } - return j -} - func hash(u, shift uint32) uint32 { return (u * 0x1e35a7bd) >> shift } diff --git a/s2/cmd/internal/readahead/reader.go b/s2/cmd/internal/readahead/reader.go index 9686b677ff..42026e38c3 100644 --- a/s2/cmd/internal/readahead/reader.go +++ b/s2/cmd/internal/readahead/reader.go @@ -293,8 +293,8 @@ func (a *reader) initBuffers(rd io.Reader, buffers [][]byte, size int) { a.in = rd a.ready = make(chan *buffer, len(buffers)) a.reuse = make(chan *buffer, len(buffers)) - a.exit = make(chan struct{}, 0) - a.exited = make(chan struct{}, 0) + a.exit = make(chan struct{}) + a.exited = make(chan struct{}) a.buffers = len(buffers) a.size = size a.cur = nil diff --git a/s2/encode_all.go b/s2/encode_all.go index 11657f0949..5e57995d48 100644 --- a/s2/encode_all.go +++ b/s2/encode_all.go @@ -742,7 +742,6 @@ searchDict: x := load64(src, s-2) m2Hash := hash6(x, tableBits) currHash := hash6(x>>8, tableBits) - candidate = int(table[currHash]) table[m2Hash] = uint32(s - 2) table[currHash] = uint32(s - 1) cv = load64(src, s) diff --git a/s2/encode_better.go b/s2/encode_better.go index f46adb4117..9436a5b8ba 100644 --- a/s2/encode_better.go +++ b/s2/encode_better.go @@ -157,7 +157,6 @@ func encodeBlockBetterGo(dst, src []byte) (d int) { index0 := base + 1 index1 := s - 2 - cv = load64(src, s) for index0 < index1 { cv0 := load64(src, index0) cv1 := load64(src, index1) @@ -599,7 +598,6 @@ searchDict: if s >= sLimit { break searchDict } - cv = load64(src, s) // Index in-between index0 := base + 1 index1 := s - 2 @@ -961,7 +959,6 @@ searchDict: index0 := base + 1 index1 := s - 2 - cv = load64(src, s) for index0 < index1 { cv0 := load64(src, index0) cv1 := load64(src, index1) diff --git a/s2/writer.go b/s2/writer.go index 5a944068cf..089cd36d8c 100644 --- a/s2/writer.go +++ b/s2/writer.go @@ -771,7 +771,7 @@ func (w *Writer) closeIndex(idx bool) ([]byte, error) { } var index []byte - if w.err(nil) == nil && w.writer != nil { + if w.err(err) == nil && w.writer != nil { // Create index. if idx { compSize := int64(-1) diff --git a/zip/reader.go b/zip/reader.go index 65aab5bf20..460394ca1f 100644 --- a/zip/reader.go +++ b/zip/reader.go @@ -715,12 +715,8 @@ func (f *fileListEntry) Info() (fs.FileInfo, error) { return f, nil } func toValidName(name string) string { name = strings.ReplaceAll(name, `\`, `/`) p := path.Clean(name) - if strings.HasPrefix(p, "/") { - p = p[len("/"):] - } - for strings.HasPrefix(p, "../") { - p = p[len("../"):] - } + p = strings.TrimPrefix(p, "/") + p = strings.TrimPrefix(p, "../") return p } diff --git a/zip/writer.go b/zip/writer.go index 0eb0378246..d3ef0eb8da 100644 --- a/zip/writer.go +++ b/zip/writer.go @@ -433,6 +433,7 @@ func min64(x, y uint64) uint64 { return y } +// CreateHeaderRaw is replaced by CreateRaw. // Deprecated: CreateHeaderRaw is replaced by CreateRaw (stdlib name). func (w *Writer) CreateHeaderRaw(fh *FileHeader) (io.Writer, error) { return w.CreateRaw(fh) diff --git a/zstd/decoder_options.go b/zstd/decoder_options.go index 07a90dd7af..774c5f00fe 100644 --- a/zstd/decoder_options.go +++ b/zstd/decoder_options.go @@ -107,7 +107,7 @@ func WithDecoderDicts(dicts ...[]byte) DOption { } } -// WithEncoderDictRaw registers a dictionary that may be used by the decoder. +// WithDecoderDictRaw registers a dictionary that may be used by the decoder. // The slice content can be arbitrary data. func WithDecoderDictRaw(id uint32, content []byte) DOption { return func(o *decoderOptions) error { diff --git a/zstd/enc_fast.go b/zstd/enc_fast.go index 315b1a8f2f..cbc626eec6 100644 --- a/zstd/enc_fast.go +++ b/zstd/enc_fast.go @@ -133,8 +133,7 @@ encodeLoop: if canRepeat && repIndex >= 0 && load3232(src, repIndex) == uint32(cv>>16) { // Consider history as well. var seq seq - var length int32 - length = 4 + e.matchlen(s+6, repIndex+4, src) + length := 4 + e.matchlen(s+6, repIndex+4, src) seq.matchLen = uint32(length - zstdMinMatch) // We might be able to match backwards. @@ -645,8 +644,7 @@ encodeLoop: if canRepeat && repIndex >= 0 && load3232(src, repIndex) == uint32(cv>>16) { // Consider history as well. var seq seq - var length int32 - length = 4 + e.matchlen(s+6, repIndex+4, src) + length := 4 + e.matchlen(s+6, repIndex+4, src) seq.matchLen = uint32(length - zstdMinMatch) diff --git a/zstd/framedec.go b/zstd/framedec.go index cc0aa22745..53e160f7e5 100644 --- a/zstd/framedec.go +++ b/zstd/framedec.go @@ -73,20 +73,20 @@ func (d *frameDec) reset(br byteBuffer) error { switch err { case io.EOF, io.ErrUnexpectedEOF: return io.EOF - default: - return err case nil: signature[0] = b[0] + default: + return err } // Read the rest, don't allow io.ErrUnexpectedEOF b, err = br.readSmall(3) switch err { case io.EOF: return io.EOF - default: - return err case nil: copy(signature[1:], b) + default: + return err } if string(signature[1:4]) != skippableFrameMagic || signature[0]&0xf0 != 0x50 {