diff options
Diffstat (limited to 'internal/compress')
| -rw-r--r-- | internal/compress/flate/deflate.go | 6 | ||||
| -rw-r--r-- | internal/compress/flate/deflate_test.go | 6 | ||||
| -rw-r--r-- | internal/compress/flate/dict_decoder_test.go | 193 | ||||
| -rw-r--r-- | internal/compress/flate/flate_test.go | 14 | ||||
| -rw-r--r-- | internal/compress/flate/fuzz_test.go | 14 | ||||
| -rw-r--r-- | internal/compress/flate/huffman_bit_writer.go | 20 | ||||
| -rw-r--r-- | internal/compress/flate/huffman_bit_writer_test.go | 14 | ||||
| -rw-r--r-- | internal/compress/flate/huffman_code.go | 6 | ||||
| -rw-r--r-- | internal/compress/flate/huffman_sortByLiteral.go | 2 | ||||
| -rw-r--r-- | internal/compress/flate/inflate.go | 6 | ||||
| -rw-r--r-- | internal/compress/flate/inflate_test.go | 1 | ||||
| -rw-r--r-- | internal/compress/flate/level3.go | 3 | ||||
| -rw-r--r-- | internal/compress/flate/token.go | 4 | ||||
| -rw-r--r-- | internal/compress/flate/writer_test.go | 2 | ||||
| -rw-r--r-- | internal/compress/internal/fuzz/helpers.go | 2 | ||||
| -rw-r--r-- | internal/compress/internal/le/unsafe_enabled.go | 16 |
16 files changed, 234 insertions, 75 deletions
diff --git a/internal/compress/flate/deflate.go b/internal/compress/flate/deflate.go index ac4a2344..d8a1ff2a 100644 --- a/internal/compress/flate/deflate.go +++ b/internal/compress/flate/deflate.go @@ -132,7 +132,7 @@ func (d *compressor) fillDeflate(b []byte) int { s := d.state if s.index >= 2*windowSize-(minMatchLength+maxMatchLength) { // shift the window by windowSize - //copy(d.window[:], d.window[windowSize:2*windowSize]) + // copy(d.window[:], d.window[windowSize:2*windowSize]) *(*[windowSize]byte)(d.window) = *(*[windowSize]byte)(d.window[windowSize:]) s.index -= windowSize d.windowEnd -= windowSize @@ -176,7 +176,7 @@ func (d *compressor) writeBlock(tok *tokens, index int, eof bool) error { window = d.window[d.blockStart:index] } d.blockStart = index - //d.w.writeBlock(tok, eof, window) + // d.w.writeBlock(tok, eof, window) d.w.writeBlockDynamic(tok, eof, window, d.sync) return d.w.err } @@ -325,7 +325,7 @@ func (d *compressor) findMatch(pos int, prevHead int, lookahead int) (length, of // Calculate gain. Estimate newGain := d.h.bitLengthRaw(wPos[:n]) - int(offsetExtraBits[offsetCode(uint32(pos-i))]) - baseCost - int(lengthExtraBits[lengthCodes[(n-3)&255]]) - //fmt.Println("gain:", newGain, "prev:", cGain, "raw:", d.h.bitLengthRaw(wPos[:n]), "this-len:", n, "prev-len:", length) + // fmt.Println("gain:", newGain, "prev:", cGain, "raw:", d.h.bitLengthRaw(wPos[:n]), "this-len:", n, "prev-len:", length) if newGain > cGain { length = n offset = pos - i diff --git a/internal/compress/flate/deflate_test.go b/internal/compress/flate/deflate_test.go index 8e082968..9ac3da1f 100644 --- a/internal/compress/flate/deflate_test.go +++ b/internal/compress/flate/deflate_test.go @@ -40,7 +40,9 @@ var deflateTests = []*deflateTest{ 4: {[]byte{0x11}, 0, []byte{0x0, 0x1, 0x0, 0xfe, 0xff, 0x11, 0x3, 0x0}}, 5: {[]byte{0x11, 0x12}, 0, []byte{0x0, 0x2, 0x0, 0xfd, 0xff, 0x11, 0x12, 0x3, 0x0}}, - 6: {[]byte{0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11}, 0, + 6: { + []byte{0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11}, + 0, []byte{0x0, 0x8, 0x0, 0xf7, 0xff, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x3, 0x0}, }, 7: {[]byte{}, 1, []byte{0x3, 0x0}}, @@ -101,7 +103,7 @@ func TestBulkHash4(t *testing.T) { } else if got != expect { t.Errorf("Len:%d Index:%d, got 0x%08x expected:0x%08x", len(y), i, got, expect) } else { - //t.Logf("Len:%d Index:%d OK (0x%08x)", len(y), i, got) + // t.Logf("Len:%d Index:%d OK (0x%08x)", len(y), i, got) } } } diff --git a/internal/compress/flate/dict_decoder_test.go b/internal/compress/flate/dict_decoder_test.go index 9275cff7..8bc48a3e 100644 --- a/internal/compress/flate/dict_decoder_test.go +++ b/internal/compress/flate/dict_decoder_test.go @@ -41,38 +41,183 @@ func TestDictDecoder(t *testing.T) { "And that has made all the difference.\n" ) - var poemRefs = []struct { + poemRefs := []struct { dist int // Backward distance (0 if this is an insertion) length int // Length of copy or insertion }{ - {0, 38}, {33, 3}, {0, 48}, {79, 3}, {0, 11}, {34, 5}, {0, 6}, {23, 7}, - {0, 8}, {50, 3}, {0, 2}, {69, 3}, {34, 5}, {0, 4}, {97, 3}, {0, 4}, - {43, 5}, {0, 6}, {7, 4}, {88, 7}, {0, 12}, {80, 3}, {0, 2}, {141, 4}, - {0, 1}, {196, 3}, {0, 3}, {157, 3}, {0, 6}, {181, 3}, {0, 2}, {23, 3}, - {77, 3}, {28, 5}, {128, 3}, {110, 4}, {70, 3}, {0, 4}, {85, 6}, {0, 2}, - {182, 6}, {0, 4}, {133, 3}, {0, 7}, {47, 5}, {0, 20}, {112, 5}, {0, 1}, - {58, 3}, {0, 8}, {59, 3}, {0, 4}, {173, 3}, {0, 5}, {114, 3}, {0, 4}, - {92, 5}, {0, 2}, {71, 3}, {0, 2}, {76, 5}, {0, 1}, {46, 3}, {96, 4}, - {130, 4}, {0, 3}, {360, 3}, {0, 3}, {178, 5}, {0, 7}, {75, 3}, {0, 3}, - {45, 6}, {0, 6}, {299, 6}, {180, 3}, {70, 6}, {0, 1}, {48, 3}, {66, 4}, - {0, 3}, {47, 5}, {0, 9}, {325, 3}, {0, 1}, {359, 3}, {318, 3}, {0, 2}, - {199, 3}, {0, 1}, {344, 3}, {0, 3}, {248, 3}, {0, 10}, {310, 3}, {0, 3}, - {93, 6}, {0, 3}, {252, 3}, {157, 4}, {0, 2}, {273, 5}, {0, 14}, {99, 4}, - {0, 1}, {464, 4}, {0, 2}, {92, 4}, {495, 3}, {0, 1}, {322, 4}, {16, 4}, - {0, 3}, {402, 3}, {0, 2}, {237, 4}, {0, 2}, {432, 4}, {0, 1}, {483, 5}, - {0, 2}, {294, 4}, {0, 2}, {306, 3}, {113, 5}, {0, 1}, {26, 4}, {164, 3}, - {488, 4}, {0, 1}, {542, 3}, {248, 6}, {0, 5}, {205, 3}, {0, 8}, {48, 3}, - {449, 6}, {0, 2}, {192, 3}, {328, 4}, {9, 5}, {433, 3}, {0, 3}, {622, 25}, - {615, 5}, {46, 5}, {0, 2}, {104, 3}, {475, 10}, {549, 3}, {0, 4}, {597, 8}, - {314, 3}, {0, 1}, {473, 6}, {317, 5}, {0, 1}, {400, 3}, {0, 3}, {109, 3}, - {151, 3}, {48, 4}, {0, 4}, {125, 3}, {108, 3}, {0, 2}, + {0, 38}, + {33, 3}, + {0, 48}, + {79, 3}, + {0, 11}, + {34, 5}, + {0, 6}, + {23, 7}, + {0, 8}, + {50, 3}, + {0, 2}, + {69, 3}, + {34, 5}, + {0, 4}, + {97, 3}, + {0, 4}, + {43, 5}, + {0, 6}, + {7, 4}, + {88, 7}, + {0, 12}, + {80, 3}, + {0, 2}, + {141, 4}, + {0, 1}, + {196, 3}, + {0, 3}, + {157, 3}, + {0, 6}, + {181, 3}, + {0, 2}, + {23, 3}, + {77, 3}, + {28, 5}, + {128, 3}, + {110, 4}, + {70, 3}, + {0, 4}, + {85, 6}, + {0, 2}, + {182, 6}, + {0, 4}, + {133, 3}, + {0, 7}, + {47, 5}, + {0, 20}, + {112, 5}, + {0, 1}, + {58, 3}, + {0, 8}, + {59, 3}, + {0, 4}, + {173, 3}, + {0, 5}, + {114, 3}, + {0, 4}, + {92, 5}, + {0, 2}, + {71, 3}, + {0, 2}, + {76, 5}, + {0, 1}, + {46, 3}, + {96, 4}, + {130, 4}, + {0, 3}, + {360, 3}, + {0, 3}, + {178, 5}, + {0, 7}, + {75, 3}, + {0, 3}, + {45, 6}, + {0, 6}, + {299, 6}, + {180, 3}, + {70, 6}, + {0, 1}, + {48, 3}, + {66, 4}, + {0, 3}, + {47, 5}, + {0, 9}, + {325, 3}, + {0, 1}, + {359, 3}, + {318, 3}, + {0, 2}, + {199, 3}, + {0, 1}, + {344, 3}, + {0, 3}, + {248, 3}, + {0, 10}, + {310, 3}, + {0, 3}, + {93, 6}, + {0, 3}, + {252, 3}, + {157, 4}, + {0, 2}, + {273, 5}, + {0, 14}, + {99, 4}, + {0, 1}, + {464, 4}, + {0, 2}, + {92, 4}, + {495, 3}, + {0, 1}, + {322, 4}, + {16, 4}, + {0, 3}, + {402, 3}, + {0, 2}, + {237, 4}, + {0, 2}, + {432, 4}, + {0, 1}, + {483, 5}, + {0, 2}, + {294, 4}, + {0, 2}, + {306, 3}, + {113, 5}, + {0, 1}, + {26, 4}, + {164, 3}, + {488, 4}, + {0, 1}, + {542, 3}, + {248, 6}, + {0, 5}, + {205, 3}, + {0, 8}, + {48, 3}, + {449, 6}, + {0, 2}, + {192, 3}, + {328, 4}, + {9, 5}, + {433, 3}, + {0, 3}, + {622, 25}, + {615, 5}, + {46, 5}, + {0, 2}, + {104, 3}, + {475, 10}, + {549, 3}, + {0, 4}, + {597, 8}, + {314, 3}, + {0, 1}, + {473, 6}, + {317, 5}, + {0, 1}, + {400, 3}, + {0, 3}, + {109, 3}, + {151, 3}, + {48, 4}, + {0, 4}, + {125, 3}, + {108, 3}, + {0, 2}, } var got, want bytes.Buffer var dd dictDecoder dd.init(1<<11, nil) - var writeCopy = func(dist, length int) { + writeCopy := func(dist, length int) { for length > 0 { cnt := dd.tryWriteCopy(dist, length) if cnt == 0 { @@ -85,7 +230,7 @@ func TestDictDecoder(t *testing.T) { } } } - var writeString = func(str string) { + writeString := func(str string) { for len(str) > 0 { cnt := copy(dd.writeSlice(), str) str = str[cnt:] diff --git a/internal/compress/flate/flate_test.go b/internal/compress/flate/flate_test.go index 9817efef..7b019548 100644 --- a/internal/compress/flate/flate_test.go +++ b/internal/compress/flate/flate_test.go @@ -21,9 +21,11 @@ import ( // The following test should not panic. func TestIssue5915(t *testing.T) { - bits := []int{4, 0, 0, 6, 4, 3, 2, 3, 3, 4, 4, 5, 0, 0, 0, 0, 5, 5, 6, + bits := []int{ + 4, 0, 0, 6, 4, 3, 2, 3, 3, 4, 4, 5, 0, 0, 0, 0, 5, 5, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 11, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 8, 6, 0, 11, 0, 8, 0, 6, 6, 10, 8} + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 8, 6, 0, 11, 0, 8, 0, 6, 6, 10, 8, + } var h huffmanDecoder if h.init(bits) { t.Fatalf("Given sequence of bits is bad, and should not succeed.") @@ -32,8 +34,10 @@ func TestIssue5915(t *testing.T) { // The following test should not panic. func TestIssue5962(t *testing.T) { - bits := []int{4, 0, 0, 6, 4, 3, 2, 3, 3, 4, 4, 5, 0, 0, 0, 0, - 5, 5, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 11} + bits := []int{ + 4, 0, 0, 6, 4, 3, 2, 3, 3, 4, 4, 5, 0, 0, 0, 0, + 5, 5, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 11, + } var h huffmanDecoder if h.init(bits) { t.Fatalf("Given sequence of bits is bad, and should not succeed.") @@ -164,7 +168,7 @@ func TestRegressions(t *testing.T) { t.Error(err) } if !bytes.Equal(data1, data2) { - //fmt.Printf("want:%x\ngot: %x\n", data1, data2) + // fmt.Printf("want:%x\ngot: %x\n", data1, data2) t.Error("not equal") } }) diff --git a/internal/compress/flate/fuzz_test.go b/internal/compress/flate/fuzz_test.go index b97cd055..5c361956 100644 --- a/internal/compress/flate/fuzz_test.go +++ b/internal/compress/flate/fuzz_test.go @@ -14,11 +14,13 @@ import ( ) // Fuzzing tweaks: -var fuzzStartF = flag.Int("start", HuffmanOnly, "Start fuzzing at this level") -var fuzzEndF = flag.Int("end", BestCompression, "End fuzzing at this level (inclusive)") -var fuzzMaxF = flag.Int("max", 1<<20, "Maximum input size") -var fuzzSLF = flag.Bool("sl", true, "Include stateless encodes") -var fuzzWindow = flag.Bool("windows", true, "Include windowed encodes") +var ( + fuzzStartF = flag.Int("start", HuffmanOnly, "Start fuzzing at this level") + fuzzEndF = flag.Int("end", BestCompression, "End fuzzing at this level (inclusive)") + fuzzMaxF = flag.Int("max", 1<<20, "Maximum input size") + fuzzSLF = flag.Bool("sl", true, "Include stateless encodes") + fuzzWindow = flag.Bool("windows", true, "Include windowed encodes") +) func TestMain(m *testing.M) { flag.Parse() @@ -118,7 +120,7 @@ func FuzzEncoding(f *testing.F) { t.Error(err) } if !bytes.Equal(data, data2) { - //fmt.Printf("want:%x\ngot: %x\n", data1, data2) + // fmt.Printf("want:%x\ngot: %x\n", data1, data2) t.Error(msg + "not equal") } } diff --git a/internal/compress/flate/huffman_bit_writer.go b/internal/compress/flate/huffman_bit_writer.go index aeab2043..aff3c960 100644 --- a/internal/compress/flate/huffman_bit_writer.go +++ b/internal/compress/flate/huffman_bit_writer.go @@ -70,7 +70,7 @@ var offsetExtraBits = [32]int8{ var offsetCombined = [32]uint32{} func init() { - var offsetBase = [32]uint32{ + offsetBase := [32]uint32{ /* normal deflate */ 0x000000, 0x000001, 0x000002, 0x000003, 0x000004, 0x000006, 0x000008, 0x00000c, 0x000010, 0x000018, @@ -475,7 +475,7 @@ func (w *huffmanBitWriter) writeDynamicHeader(numLiterals int, numOffsets int, n i := 0 for { - var codeWord = uint32(w.codegen[i]) + codeWord := uint32(w.codegen[i]) i++ if codeWord == badCode { break @@ -572,9 +572,9 @@ func (w *huffmanBitWriter) writeBlock(tokens *tokens, eof bool, input []byte) { // Figure out smallest code. // Fixed Huffman baseline. - var literalEncoding = fixedLiteralEncoding - var offsetEncoding = fixedOffsetEncoding - var size = math.MaxInt32 + literalEncoding := fixedLiteralEncoding + offsetEncoding := fixedOffsetEncoding + size := math.MaxInt32 if tokens.n < maxPredefinedTokens { size = w.fixedSize(extraBits) } @@ -782,9 +782,9 @@ func (w *huffmanBitWriter) fillTokens() { // and offsetEncoding. // The number of literal and offset tokens is returned. func (w *huffmanBitWriter) indexTokens(t *tokens, alwaysEOB bool) (numLiterals, numOffsets int) { - //copy(w.literalFreq[:], t.litHist[:]) + // copy(w.literalFreq[:], t.litHist[:]) *(*[256]uint16)(w.literalFreq[:]) = t.litHist - //copy(w.literalFreq[256:], t.extraHist[:]) + // copy(w.literalFreq[256:], t.extraHist[:]) *(*[32]uint16)(w.literalFreq[256:]) = t.extraHist w.offsetFreq = t.offHist @@ -847,7 +847,7 @@ func (w *huffmanBitWriter) writeTokens(tokens []token, leCodes, oeCodes []hcode) for _, t := range tokens { if t < 256 { - //w.writeCode(lits[t.literal()]) + // w.writeCode(lits[t.literal()]) c := lits[t] bits |= c.code64() << (nbits & 63) nbits += c.len() @@ -896,7 +896,7 @@ func (w *huffmanBitWriter) writeTokens(tokens []token, leCodes, oeCodes []hcode) if lengthCode >= lengthExtraBitsMinCode { extraLengthBits := lengthExtraBits[lengthCode] - //w.writeBits(extraLength, extraLengthBits) + // w.writeBits(extraLength, extraLengthBits) extraLength := int32(length - lengthBase[lengthCode]) bits |= uint64(extraLength) << (nbits & 63) nbits += extraLengthBits @@ -943,7 +943,7 @@ func (w *huffmanBitWriter) writeTokens(tokens []token, leCodes, oeCodes []hcode) if offsetCode >= offsetExtraBitsMinCode { offsetComb := offsetCombined[offsetCode] - //w.writeBits(extraOffset, extraOffsetBits) + // w.writeBits(extraOffset, extraOffsetBits) bits |= uint64((offset-(offsetComb>>8))&matchOffsetOnlyMask) << (nbits & 63) nbits += uint8(offsetComb) if nbits >= 48 { diff --git a/internal/compress/flate/huffman_bit_writer_test.go b/internal/compress/flate/huffman_bit_writer_test.go index dfb93e32..3fc414e2 100644 --- a/internal/compress/flate/huffman_bit_writer_test.go +++ b/internal/compress/flate/huffman_bit_writer_test.go @@ -62,7 +62,7 @@ func testBlockHuff(t *testing.T, in, out string) { if *update { if in != out { t.Logf("Updating %q", out) - if err := os.WriteFile(out, got, 0666); err != nil { + if err := os.WriteFile(out, got, 0o666); err != nil { t.Error(err) } return @@ -72,7 +72,7 @@ func testBlockHuff(t *testing.T, in, out string) { } t.Errorf("%q != %q (see %q)", in, out, in+".got") - if err := os.WriteFile(in+".got", got, 0666); err != nil { + if err := os.WriteFile(in+".got", got, 0o666); err != nil { t.Error(err) } return @@ -87,7 +87,7 @@ func testBlockHuff(t *testing.T, in, out string) { got = buf.Bytes() if !bytes.Equal(got, want) { t.Errorf("after reset %q != %q (see %q)", in, out, in+".reset.got") - if err := os.WriteFile(in+".reset.got", got, 0666); err != nil { + if err := os.WriteFile(in+".reset.got", got, 0o666); err != nil { t.Error(err) } return @@ -245,7 +245,7 @@ func testBlock(t *testing.T, test huffTest, ttype string) { got := buf.Bytes() if !bytes.Equal(got, want) { t.Errorf("writeBlock did not yield expected result for file %q with input. See %q", test.want, test.want+gotSuffix) - if err := os.WriteFile(test.want+gotSuffix, got, 0666); err != nil { + if err := os.WriteFile(test.want+gotSuffix, got, 0o666); err != nil { t.Error(err) } } @@ -259,7 +259,7 @@ func testBlock(t *testing.T, test huffTest, ttype string) { got = buf.Bytes() if !bytes.Equal(got, want) { t.Errorf("reset: writeBlock did not yield expected result for file %q with input. See %q", test.want, test.want+".reset"+gotSuffix) - if err := os.WriteFile(test.want+".reset"+gotSuffix, got, 0666); err != nil { + if err := os.WriteFile(test.want+".reset"+gotSuffix, got, 0o666); err != nil { t.Error(err) } return @@ -280,7 +280,7 @@ func testBlock(t *testing.T, test huffTest, ttype string) { got := buf.Bytes() if !bytes.Equal(got, wantNI) { t.Errorf("writeBlock did not yield expected result for file %q with input. See %q", test.wantNoInput, test.wantNoInput+gotSuffix) - if err := os.WriteFile(test.wantNoInput+gotSuffix, got, 0666); err != nil { + if err := os.WriteFile(test.wantNoInput+gotSuffix, got, 0o666); err != nil { t.Error(err) } } else if got[0]&1 == 1 { @@ -298,7 +298,7 @@ func testBlock(t *testing.T, test huffTest, ttype string) { got = buf.Bytes() if !bytes.Equal(got, wantNI) { t.Errorf("reset: writeBlock did not yield expected result for file %q without input. See %q", test.wantNoInput, test.wantNoInput+".reset"+gotSuffix) - if err := os.WriteFile(test.wantNoInput+".reset"+gotSuffix, got, 0666); err != nil { + if err := os.WriteFile(test.wantNoInput+".reset"+gotSuffix, got, 0o666); err != nil { t.Error(err) } return diff --git a/internal/compress/flate/huffman_code.go b/internal/compress/flate/huffman_code.go index 5f901bd0..42da87e8 100644 --- a/internal/compress/flate/huffman_code.go +++ b/internal/compress/flate/huffman_code.go @@ -126,8 +126,10 @@ func generateFixedOffsetEncoding() *huffmanEncoder { return h } -var fixedLiteralEncoding = generateFixedLiteralEncoding() -var fixedOffsetEncoding = generateFixedOffsetEncoding() +var ( + fixedLiteralEncoding = generateFixedLiteralEncoding() + fixedOffsetEncoding = generateFixedOffsetEncoding() +) func (h *huffmanEncoder) bitLength(freq []uint16) int { var total int diff --git a/internal/compress/flate/huffman_sortByLiteral.go b/internal/compress/flate/huffman_sortByLiteral.go index 93f1aea1..f6d0a404 100644 --- a/internal/compress/flate/huffman_sortByLiteral.go +++ b/internal/compress/flate/huffman_sortByLiteral.go @@ -41,6 +41,7 @@ func quickSort(data []literalNode, a, b, maxDepth int) { insertionSort(data, a, b) } } + func heapSort(data []literalNode, a, b int) { first := a lo := 0 @@ -77,6 +78,7 @@ func siftDown(data []literalNode, lo, hi, first int) { root = child } } + func doPivot(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/internal/compress/flate/inflate.go b/internal/compress/flate/inflate.go index d200d244..eeee6ab7 100644 --- a/internal/compress/flate/inflate.go +++ b/internal/compress/flate/inflate.go @@ -44,8 +44,10 @@ var bitMask32 = [32]uint32{ } // up to 32 bits // Initialize the fixedHuffmanDecoder only once upon first use. -var fixedOnce sync.Once -var fixedHuffmanDecoder huffmanDecoder +var ( + fixedOnce sync.Once + fixedHuffmanDecoder huffmanDecoder +) // A CorruptInputError reports the presence of corrupt input at a given offset. type CorruptInputError = flate.CorruptInputError diff --git a/internal/compress/flate/inflate_test.go b/internal/compress/flate/inflate_test.go index d018991c..7a58739b 100644 --- a/internal/compress/flate/inflate_test.go +++ b/internal/compress/flate/inflate_test.go @@ -190,7 +190,6 @@ func TestInflate(t *testing.T) { } t.Fatal(test.err, err) } - } // Tests ported from zlib/test/infcover.c diff --git a/internal/compress/flate/level3.go b/internal/compress/flate/level3.go index 33f9fb15..2cef0290 100644 --- a/internal/compress/flate/level3.go +++ b/internal/compress/flate/level3.go @@ -181,7 +181,8 @@ func (e *fastEncL3) Encode(dst *tokens, src []byte) { nextHash := hashLen(load6432(src, i), tableBits, hashBytes) e.table[nextHash] = tableEntryPrev{ Prev: e.table[nextHash].Cur, - Cur: tableEntry{offset: e.cur + i}} + Cur: tableEntry{offset: e.cur + i}, + } } // We could immediately start working at s now, but to improve // compression we first update the hash table at s-2 to s. diff --git a/internal/compress/flate/token.go b/internal/compress/flate/token.go index d818790c..40fa9454 100644 --- a/internal/compress/flate/token.go +++ b/internal/compress/flate/token.go @@ -320,7 +320,7 @@ func (t *tokens) Slice() []token { // VarInt returns the tokens as varint encoded bytes. func (t *tokens) VarInt() []byte { - var b = make([]byte, binary.MaxVarintLen32*int(t.n)) + b := make([]byte, binary.MaxVarintLen32*int(t.n)) var off int for _, v := range t.tokens[:t.n] { off += binary.PutUvarint(b[off:], uint64(v)) @@ -331,7 +331,7 @@ func (t *tokens) VarInt() []byte { // FromVarInt restores t to the varint encoded tokens provided. // Any data in t is removed. func (t *tokens) FromVarInt(b []byte) error { - var buf = bytes.NewReader(b) + buf := bytes.NewReader(b) var toks []token for { r, err := binary.ReadUvarint(buf) diff --git a/internal/compress/flate/writer_test.go b/internal/compress/flate/writer_test.go index ea448298..01893e50 100644 --- a/internal/compress/flate/writer_test.go +++ b/internal/compress/flate/writer_test.go @@ -405,7 +405,7 @@ func TestDeterministicLM2(t *testing.T) { testDeterministic(-2, t) } func testDeterministic(i int, t *testing.T) { // Test so much we cross a good number of block boundaries. - var length = maxStoreBlockSize*30 + 500 + length := maxStoreBlockSize*30 + 500 if testing.Short() { length /= 10 } diff --git a/internal/compress/internal/fuzz/helpers.go b/internal/compress/internal/fuzz/helpers.go index ff32ce49..71332ac6 100644 --- a/internal/compress/internal/fuzz/helpers.go +++ b/internal/compress/internal/fuzz/helpers.go @@ -165,7 +165,7 @@ func unmarshalCorpusFile(b []byte) ([][]byte, error) { if len(lines) < 2 { return nil, fmt.Errorf("must include version and at least one value") } - var vals = make([][]byte, 0, len(lines)-1) + vals := make([][]byte, 0, len(lines)-1) for _, line := range lines[1:] { line = bytes.TrimSpace(line) if len(line) == 0 { diff --git a/internal/compress/internal/le/unsafe_enabled.go b/internal/compress/internal/le/unsafe_enabled.go index 218a38bc..b47fd0db 100644 --- a/internal/compress/internal/le/unsafe_enabled.go +++ b/internal/compress/internal/le/unsafe_enabled.go @@ -10,29 +10,29 @@ import ( // Load8 will load from b at index i. func Load8[I Indexer](b []byte, i I) byte { - //return binary.LittleEndian.Uint16(b[i:]) - //return *(*uint16)(unsafe.Pointer(&b[i])) + // return binary.LittleEndian.Uint16(b[i:]) + // return *(*uint16)(unsafe.Pointer(&b[i])) return *(*byte)(unsafe.Add(unsafe.Pointer(unsafe.SliceData(b)), i)) } // Load16 will load from b at index i. func Load16[I Indexer](b []byte, i I) uint16 { - //return binary.LittleEndian.Uint16(b[i:]) - //return *(*uint16)(unsafe.Pointer(&b[i])) + // return binary.LittleEndian.Uint16(b[i:]) + // return *(*uint16)(unsafe.Pointer(&b[i])) return *(*uint16)(unsafe.Add(unsafe.Pointer(unsafe.SliceData(b)), i)) } // Load32 will load from b at index i. func Load32[I Indexer](b []byte, i I) uint32 { - //return binary.LittleEndian.Uint32(b[i:]) - //return *(*uint32)(unsafe.Pointer(&b[i])) + // return binary.LittleEndian.Uint32(b[i:]) + // return *(*uint32)(unsafe.Pointer(&b[i])) return *(*uint32)(unsafe.Add(unsafe.Pointer(unsafe.SliceData(b)), i)) } // Load64 will load from b at index i. func Load64[I Indexer](b []byte, i I) uint64 { - //return binary.LittleEndian.Uint64(b[i:]) - //return *(*uint64)(unsafe.Pointer(&b[i])) + // return binary.LittleEndian.Uint64(b[i:]) + // return *(*uint64)(unsafe.Pointer(&b[i])) return *(*uint64)(unsafe.Add(unsafe.Pointer(unsafe.SliceData(b)), i)) } |
