Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
build:
strategy:
matrix:
go-version: [1.22.x, 1.23.x, 1.24.x]
go-version: [1.23.x, 1.24.x, 1.25.x]
os: [ubuntu-latest, macos-latest, windows-latest]
env:
CGO_ENABLED: 0
Expand Down Expand Up @@ -60,7 +60,7 @@ jobs:
- name: Set up Go
uses: actions/setup-go@v5.5.0
with:
go-version: 1.24.x
go-version: 1.25.x

- name: Checkout code
uses: actions/checkout@v4
Expand All @@ -82,7 +82,7 @@ jobs:
- name: Set up Go
uses: actions/setup-go@v5.5.0
with:
go-version: 1.24.x
go-version: 1.25.x

- name: Checkout code
uses: actions/checkout@v4
Expand Down Expand Up @@ -125,7 +125,7 @@ jobs:
- name: Set up Go
uses: actions/setup-go@v5.5.0
with:
go-version: 1.24.x
go-version: 1.25.x

- name: Checkout code
uses: actions/checkout@v4
Expand All @@ -151,7 +151,7 @@ jobs:
- name: Set up Go
uses: actions/setup-go@v5.5.0
with:
go-version: 1.24.x
go-version: 1.25.x

- name: Checkout code
uses: actions/checkout@v4
Expand Down Expand Up @@ -182,7 +182,7 @@ jobs:
- name: Set up Go
uses: actions/setup-go@v5.5.0
with:
go-version: 1.24.x
go-version: 1.25.x
- name: Checkout code
uses: actions/checkout@v4

Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@ jobs:
name: Set up Go
uses: actions/setup-go@d35c59abb061a4a6fb18e82ac0862c26744d6ab5 # v5.2.0
with:
go-version: 1.24.x
go-version: 1.25.x
-
name: Run GoReleaser
uses: goreleaser/goreleaser-action@9c156ee8a17a598857849441385a2041ef570552 # v6.3.0
with:
version: 2.3.2
version: 2.11.2
args: release --clean
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
Expand Down
9 changes: 3 additions & 6 deletions dict/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,12 +103,12 @@ func buildDict(input [][]byte, o Options) ([]byte, error) {
if hashBytes < 4 || hashBytes > 8 {
return nil, fmt.Errorf("HashBytes must be >= 4 and <= 8")
}
println := func(args ...interface{}) {
println := func(args ...any) {
if o.Output != nil {
fmt.Fprintln(o.Output, args...)
}
}
printf := func(s string, args ...interface{}) {
printf := func(s string, args ...any) {
if o.Output != nil {
fmt.Fprintf(o.Output, s, args...)
}
Expand Down Expand Up @@ -237,10 +237,7 @@ func buildDict(input [][]byte, o Options) ([]byte, error) {
// Already added
continue
}
wantLen := e.n / uint32(hashBytes) / 4
if wantLen <= lowestOcc {
wantLen = lowestOcc
}
wantLen := max(e.n/uint32(hashBytes)/4, lowestOcc)

var tmp = make([]byte, 0, hashBytes*2)
{
Expand Down
42 changes: 9 additions & 33 deletions flate/deflate.go
Original file line number Diff line number Diff line change
Expand Up @@ -234,12 +234,9 @@ func (d *compressor) fillWindow(b []byte) {

// Calculate 256 hashes at the time (more L1 cache hits)
loops := (n + 256 - minMatchLength) / 256
for j := 0; j < loops; j++ {
for j := range loops {
startindex := j * 256
end := startindex + 256 + minMatchLength - 1
if end > n {
end = n
}
end := min(startindex+256+minMatchLength-1, n)
tocheck := d.window[startindex:end]
dstSize := len(tocheck) - minMatchLength + 1

Expand Down Expand Up @@ -269,29 +266,20 @@ func (d *compressor) fillWindow(b []byte) {
// We only look at chainCount possibilities before giving up.
// pos = s.index, prevHead = s.chainHead-s.hashOffset, prevLength=minMatchLength-1, lookahead
func (d *compressor) findMatch(pos int, prevHead int, lookahead int) (length, offset int, ok bool) {
minMatchLook := maxMatchLength
if lookahead < minMatchLook {
minMatchLook = lookahead
}
minMatchLook := min(lookahead, maxMatchLength)

win := d.window[0 : pos+minMatchLook]

// We quit when we get a match that's at least nice long
nice := len(win) - pos
if d.nice < nice {
nice = d.nice
}
nice := min(d.nice, len(win)-pos)

// If we've got a match that's good enough, only look in 1/4 the chain.
tries := d.chain
length = minMatchLength - 1

wEnd := win[pos+length]
wPos := win[pos:]
minIndex := pos - windowSize
if minIndex < 0 {
minIndex = 0
}
minIndex := max(pos-windowSize, 0)
offset = 0

if d.chain < 100 {
Expand Down Expand Up @@ -480,10 +468,7 @@ func (d *compressor) deflateLazy() {
prevOffset := s.offset
s.length = minMatchLength - 1
s.offset = 0
minIndex := s.index - windowSize
if minIndex < 0 {
minIndex = 0
}
minIndex := max(s.index-windowSize, 0)

if s.chainHead-s.hashOffset >= minIndex && lookahead > prevLength && prevLength < d.lazy {
if newLength, newOffset, ok := d.findMatch(s.index, s.chainHead-s.hashOffset, lookahead); ok {
Expand All @@ -503,10 +488,7 @@ func (d *compressor) deflateLazy() {
if prevLength < maxMatchLength-checkOff {
prevIndex := s.index - 1
if prevIndex+prevLength < s.maxInsertIndex {
end := lookahead
if lookahead > maxMatchLength+checkOff {
end = maxMatchLength + checkOff
}
end := min(lookahead, maxMatchLength+checkOff)
end += prevIndex

// Hash at match end.
Expand Down Expand Up @@ -603,15 +585,9 @@ func (d *compressor) deflateLazy() {
// table.
newIndex := s.index + prevLength - 1
// Calculate missing hashes
end := newIndex
if end > s.maxInsertIndex {
end = s.maxInsertIndex
}
end := min(newIndex, s.maxInsertIndex)
end += minMatchLength - 1
startindex := s.index + 1
if startindex > s.maxInsertIndex {
startindex = s.maxInsertIndex
}
startindex := min(s.index+1, s.maxInsertIndex)
tocheck := d.window[startindex:end]
dstSize := len(tocheck) - minMatchLength + 1
if dstSize > 0 {
Expand Down
12 changes: 6 additions & 6 deletions flate/deflate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ func testSync(t *testing.T, level int, input []byte, name string) {
r := NewReader(buf)

// Write half the input and read back.
for i := 0; i < 2; i++ {
for i := range 2 {
var lo, hi int
if i == 0 {
lo, hi = 0, (len(input)+1)/2
Expand Down Expand Up @@ -340,7 +340,7 @@ func testToFromWithLevelAndLimit(t *testing.T, level int, input []byte, name str
}

func testToFromWithLimit(t *testing.T, input []byte, name string, limit [11]int) {
for i := 0; i < 10; i++ {
for i := range 10 {
testToFromWithLevelAndLimit(t, i, input, name, limit[i])
}
testToFromWithLevelAndLimit(t, -2, input, name, limit[10])
Expand Down Expand Up @@ -470,7 +470,7 @@ func TestRegression2508(t *testing.T) {
t.Fatalf("NewWriter: %v", err)
}
buf := make([]byte, 1024)
for i := 0; i < 131072; i++ {
for range 131072 {
if _, err := w.Write(buf); err != nil {
t.Fatalf("writer failed: %v", err)
}
Expand All @@ -491,7 +491,7 @@ func TestWriterReset(t *testing.T) {
t.Fatalf("NewWriter: %v", err)
}
buf := []byte("hello world")
for i := 0; i < 1024; i++ {
for range 1024 {
w.Write(buf)
}
w.Reset(io.Discard)
Expand Down Expand Up @@ -556,15 +556,15 @@ func testResetOutput(t *testing.T, name string, newWriter func(w io.Writer) (*Wr
t.Fatalf("NewWriter: %v", err)
}
b := []byte("hello world - how are you doing?")
for i := 0; i < 1024; i++ {
for range 1024 {
w.Write(b)
}
w.Close()
out1 := buf.Bytes()

buf2 := new(bytes.Buffer)
w.Reset(buf2)
for i := 0; i < 1024; i++ {
for range 1024 {
w.Write(b)
}
w.Close()
Expand Down
5 changes: 1 addition & 4 deletions flate/dict_decoder.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,10 +104,7 @@ func (dd *dictDecoder) writeCopy(dist, length int) int {
dstBase := dd.wrPos
dstPos := dstBase
srcPos := dstPos - dist
endPos := dstPos + length
if endPos > len(dd.hist) {
endPos = len(dd.hist)
}
endPos := min(dstPos+length, len(dd.hist))

// Copy non-overlapping section after destination position.
//
Expand Down
12 changes: 3 additions & 9 deletions flate/huffman_bit_writer.go
Original file line number Diff line number Diff line change
Expand Up @@ -303,10 +303,7 @@ func (w *huffmanBitWriter) generateCodegen(numLiterals int, numOffsets int, litE
w.codegenFreq[size]++
count--
for count >= 3 {
n := 6
if n > count {
n = count
}
n := min(6, count)
codegen[outIndex] = 16
outIndex++
codegen[outIndex] = uint8(n - 3)
Expand All @@ -316,10 +313,7 @@ func (w *huffmanBitWriter) generateCodegen(numLiterals int, numOffsets int, litE
}
} else {
for count >= 11 {
n := 138
if n > count {
n = count
}
n := min(138, count)
codegen[outIndex] = 18
outIndex++
codegen[outIndex] = uint8(n - 11)
Expand Down Expand Up @@ -472,7 +466,7 @@ func (w *huffmanBitWriter) writeDynamicHeader(numLiterals int, numOffsets int, n
w.writeBits(int32(numOffsets-1), 5)
w.writeBits(int32(numCodegens-4), 4)

for i := 0; i < numCodegens; i++ {
for i := range numCodegens {
value := uint(w.codegenEncoding.codes[codegenOrder[i]].len())
w.writeBits(int32(value), 3)
}
Expand Down
2 changes: 1 addition & 1 deletion flate/huffman_code.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ func generateFixedLiteralEncoding() *huffmanEncoder {
h := newHuffmanEncoder(literalCount)
codes := h.codes
var ch uint16
for ch = 0; ch < literalCount; ch++ {
for ch = range uint16(literalCount) {
var bits uint16
var size uint8
switch {
Expand Down
4 changes: 2 additions & 2 deletions flate/inflate.go
Original file line number Diff line number Diff line change
Expand Up @@ -485,7 +485,7 @@ func (f *decompressor) readHuffman() error {
f.nb -= 5 + 5 + 4

// (HCLEN+4)*3 bits: code lengths in the magic codeOrder order.
for i := 0; i < nclen; i++ {
for i := range nclen {
for f.nb < 3 {
if err := f.moreBits(); err != nil {
return err
Expand Down Expand Up @@ -776,7 +776,7 @@ func fixedHuffmanDecoderInit() {
fixedOnce.Do(func() {
// These come from the RFC section 3.2.6.
var bits [288]int
for i := 0; i < 144; i++ {
for i := range 144 {
bits[i] = 8
}
for i := 144; i < 256; i++ {
Expand Down
5 changes: 1 addition & 4 deletions flate/level5.go
Original file line number Diff line number Diff line change
Expand Up @@ -677,10 +677,7 @@ func (e *fastEncL5Window) matchlen(s, t int32, src []byte) int32 {
panic(fmt.Sprint(s, "-", t, "(", s-t, ") > maxMatchLength (", maxMatchOffset, ")"))
}
}
s1 := int(s) + maxMatchLength - 4
if s1 > len(src) {
s1 = len(src)
}
s1 := min(int(s)+maxMatchLength-4, len(src))

// Extend the match to be as long as possible.
return int32(matchLen(src[s:s1], src[t:]))
Expand Down
4 changes: 2 additions & 2 deletions flate/stateless.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ func NewStatelessWriter(dst io.Writer) io.WriteCloser {

// bitWriterPool contains bit writers that can be reused.
var bitWriterPool = sync.Pool{
New: func() interface{} {
New: func() any {
return newHuffmanBitWriter(nil)
},
}
Expand Down Expand Up @@ -184,7 +184,7 @@ func statelessEnc(dst *tokens, src []byte, startAt int16) {
// Index until startAt
if startAt > 0 {
cv := load3232(src, 0)
for i := int16(0); i < startAt; i++ {
for i := range startAt {
table[hashSL(cv)] = tableEntry{offset: i}
cv = (cv >> 8) | (uint32(src[i+4]) << 24)
}
Expand Down
2 changes: 1 addition & 1 deletion flate/token_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
)

type testFatal interface {
Fatal(args ...interface{})
Fatal(args ...any)
}

// loadTestTokens will load test tokens.
Expand Down
8 changes: 4 additions & 4 deletions flate/writer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ func TestWriteError(t *testing.T) {
in := buf.Bytes()
// We create our own buffer to control number of writes.
copyBuf := make([]byte, 128)
for l := 0; l < 10; l++ {
for l := range 10 {
for fail := 1; fail <= 256; fail *= 2 {
// Fail after 'fail' writes
ew := &errorWriter{N: fail}
Expand Down Expand Up @@ -334,7 +334,7 @@ func TestWriter_Reset(t *testing.T) {
fmt.Fprintf(buf, "asdasfasf%d%dfghfgujyut%dyutyu\n", i, i, i)
}
in := buf.Bytes()
for l := 0; l < 10; l++ {
for l := range 10 {
l := l
if testing.Short() && l > 1 {
continue
Expand Down Expand Up @@ -364,7 +364,7 @@ func TestWriter_Reset(t *testing.T) {
if err != nil {
t.Fatal(err)
}
for i := 0; i < 50; i++ {
for range 50 {
// skip ahead again... This should wrap around...
w.d.fast.Reset()
}
Expand All @@ -374,7 +374,7 @@ func TestWriter_Reset(t *testing.T) {
if err != nil {
t.Fatal(err)
}
for i := 0; i < (math.MaxUint32-bufferReset)/maxMatchOffset; i++ {
for range (math.MaxUint32 - bufferReset) / maxMatchOffset {
// skip ahead to where we are close to wrap around...
w.d.fast.Reset()
}
Expand Down
2 changes: 1 addition & 1 deletion fse/bitwriter.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ func (b *bitWriter) flush32() {
// flushAlign will flush remaining full bytes and align to next byte boundary.
func (b *bitWriter) flushAlign() {
nbBytes := (b.nBits + 7) >> 3
for i := uint8(0); i < nbBytes; i++ {
for i := range nbBytes {
b.out = append(b.out, byte(b.bitContainer>>(i*8)))
}
b.nBits = 0
Expand Down
Loading
Loading