Skip to content

Commit c43fcbb

Browse files
authored
Run modernize. Deprecate Go 1.22 (#1095)
* Run modernize. Deprecate Go 1.22 * Update subpackages * Bump tools, ref: golang/go#74462 Running: https://pkg.go.dev/golang.org/x/tools/gopls/internal/analysis/modernize
1 parent 86a9489 commit c43fcbb

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

72 files changed

+206
-370
lines changed

.github/workflows/go.yml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ jobs:
1212
build:
1313
strategy:
1414
matrix:
15-
go-version: [1.22.x, 1.23.x, 1.24.x]
15+
go-version: [1.23.x, 1.24.x, 1.25.x]
1616
os: [ubuntu-latest, macos-latest, windows-latest]
1717
env:
1818
CGO_ENABLED: 0
@@ -60,7 +60,7 @@ jobs:
6060
- name: Set up Go
6161
uses: actions/[email protected]
6262
with:
63-
go-version: 1.24.x
63+
go-version: 1.25.x
6464

6565
- name: Checkout code
6666
uses: actions/checkout@v4
@@ -82,7 +82,7 @@ jobs:
8282
- name: Set up Go
8383
uses: actions/[email protected]
8484
with:
85-
go-version: 1.24.x
85+
go-version: 1.25.x
8686

8787
- name: Checkout code
8888
uses: actions/checkout@v4
@@ -125,7 +125,7 @@ jobs:
125125
- name: Set up Go
126126
uses: actions/[email protected]
127127
with:
128-
go-version: 1.24.x
128+
go-version: 1.25.x
129129

130130
- name: Checkout code
131131
uses: actions/checkout@v4
@@ -151,7 +151,7 @@ jobs:
151151
- name: Set up Go
152152
uses: actions/[email protected]
153153
with:
154-
go-version: 1.24.x
154+
go-version: 1.25.x
155155

156156
- name: Checkout code
157157
uses: actions/checkout@v4
@@ -182,7 +182,7 @@ jobs:
182182
- name: Set up Go
183183
uses: actions/[email protected]
184184
with:
185-
go-version: 1.24.x
185+
go-version: 1.25.x
186186
- name: Checkout code
187187
uses: actions/checkout@v4
188188

.github/workflows/release.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,12 @@ jobs:
2121
name: Set up Go
2222
uses: actions/setup-go@d35c59abb061a4a6fb18e82ac0862c26744d6ab5 # v5.2.0
2323
with:
24-
go-version: 1.24.x
24+
go-version: 1.25.x
2525
-
2626
name: Run GoReleaser
2727
uses: goreleaser/goreleaser-action@9c156ee8a17a598857849441385a2041ef570552 # v6.3.0
2828
with:
29-
version: 2.3.2
29+
version: 2.11.2
3030
args: release --clean
3131
env:
3232
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

dict/builder.go

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -103,12 +103,12 @@ func buildDict(input [][]byte, o Options) ([]byte, error) {
103103
if hashBytes < 4 || hashBytes > 8 {
104104
return nil, fmt.Errorf("HashBytes must be >= 4 and <= 8")
105105
}
106-
println := func(args ...interface{}) {
106+
println := func(args ...any) {
107107
if o.Output != nil {
108108
fmt.Fprintln(o.Output, args...)
109109
}
110110
}
111-
printf := func(s string, args ...interface{}) {
111+
printf := func(s string, args ...any) {
112112
if o.Output != nil {
113113
fmt.Fprintf(o.Output, s, args...)
114114
}
@@ -237,10 +237,7 @@ func buildDict(input [][]byte, o Options) ([]byte, error) {
237237
// Already added
238238
continue
239239
}
240-
wantLen := e.n / uint32(hashBytes) / 4
241-
if wantLen <= lowestOcc {
242-
wantLen = lowestOcc
243-
}
240+
wantLen := max(e.n/uint32(hashBytes)/4, lowestOcc)
244241

245242
var tmp = make([]byte, 0, hashBytes*2)
246243
{

flate/deflate.go

Lines changed: 9 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -234,12 +234,9 @@ func (d *compressor) fillWindow(b []byte) {
234234

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

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

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

279273
// We quit when we get a match that's at least nice long
280-
nice := len(win) - pos
281-
if d.nice < nice {
282-
nice = d.nice
283-
}
274+
nice := min(d.nice, len(win)-pos)
284275

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

289280
wEnd := win[pos+length]
290281
wPos := win[pos:]
291-
minIndex := pos - windowSize
292-
if minIndex < 0 {
293-
minIndex = 0
294-
}
282+
minIndex := max(pos-windowSize, 0)
295283
offset = 0
296284

297285
if d.chain < 100 {
@@ -480,10 +468,7 @@ func (d *compressor) deflateLazy() {
480468
prevOffset := s.offset
481469
s.length = minMatchLength - 1
482470
s.offset = 0
483-
minIndex := s.index - windowSize
484-
if minIndex < 0 {
485-
minIndex = 0
486-
}
471+
minIndex := max(s.index-windowSize, 0)
487472

488473
if s.chainHead-s.hashOffset >= minIndex && lookahead > prevLength && prevLength < d.lazy {
489474
if newLength, newOffset, ok := d.findMatch(s.index, s.chainHead-s.hashOffset, lookahead); ok {
@@ -503,10 +488,7 @@ func (d *compressor) deflateLazy() {
503488
if prevLength < maxMatchLength-checkOff {
504489
prevIndex := s.index - 1
505490
if prevIndex+prevLength < s.maxInsertIndex {
506-
end := lookahead
507-
if lookahead > maxMatchLength+checkOff {
508-
end = maxMatchLength + checkOff
509-
}
491+
end := min(lookahead, maxMatchLength+checkOff)
510492
end += prevIndex
511493

512494
// Hash at match end.
@@ -603,15 +585,9 @@ func (d *compressor) deflateLazy() {
603585
// table.
604586
newIndex := s.index + prevLength - 1
605587
// Calculate missing hashes
606-
end := newIndex
607-
if end > s.maxInsertIndex {
608-
end = s.maxInsertIndex
609-
}
588+
end := min(newIndex, s.maxInsertIndex)
610589
end += minMatchLength - 1
611-
startindex := s.index + 1
612-
if startindex > s.maxInsertIndex {
613-
startindex = s.maxInsertIndex
614-
}
590+
startindex := min(s.index+1, s.maxInsertIndex)
615591
tocheck := d.window[startindex:end]
616592
dstSize := len(tocheck) - minMatchLength + 1
617593
if dstSize > 0 {

flate/deflate_test.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ func testSync(t *testing.T, level int, input []byte, name string) {
238238
r := NewReader(buf)
239239

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

342342
func testToFromWithLimit(t *testing.T, input []byte, name string, limit [11]int) {
343-
for i := 0; i < 10; i++ {
343+
for i := range 10 {
344344
testToFromWithLevelAndLimit(t, i, input, name, limit[i])
345345
}
346346
testToFromWithLevelAndLimit(t, -2, input, name, limit[10])
@@ -470,7 +470,7 @@ func TestRegression2508(t *testing.T) {
470470
t.Fatalf("NewWriter: %v", err)
471471
}
472472
buf := make([]byte, 1024)
473-
for i := 0; i < 131072; i++ {
473+
for range 131072 {
474474
if _, err := w.Write(buf); err != nil {
475475
t.Fatalf("writer failed: %v", err)
476476
}
@@ -491,7 +491,7 @@ func TestWriterReset(t *testing.T) {
491491
t.Fatalf("NewWriter: %v", err)
492492
}
493493
buf := []byte("hello world")
494-
for i := 0; i < 1024; i++ {
494+
for range 1024 {
495495
w.Write(buf)
496496
}
497497
w.Reset(io.Discard)
@@ -556,15 +556,15 @@ func testResetOutput(t *testing.T, name string, newWriter func(w io.Writer) (*Wr
556556
t.Fatalf("NewWriter: %v", err)
557557
}
558558
b := []byte("hello world - how are you doing?")
559-
for i := 0; i < 1024; i++ {
559+
for range 1024 {
560560
w.Write(b)
561561
}
562562
w.Close()
563563
out1 := buf.Bytes()
564564

565565
buf2 := new(bytes.Buffer)
566566
w.Reset(buf2)
567-
for i := 0; i < 1024; i++ {
567+
for range 1024 {
568568
w.Write(b)
569569
}
570570
w.Close()

flate/dict_decoder.go

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -104,10 +104,7 @@ func (dd *dictDecoder) writeCopy(dist, length int) int {
104104
dstBase := dd.wrPos
105105
dstPos := dstBase
106106
srcPos := dstPos - dist
107-
endPos := dstPos + length
108-
if endPos > len(dd.hist) {
109-
endPos = len(dd.hist)
110-
}
107+
endPos := min(dstPos+length, len(dd.hist))
111108

112109
// Copy non-overlapping section after destination position.
113110
//

flate/huffman_bit_writer.go

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -303,10 +303,7 @@ func (w *huffmanBitWriter) generateCodegen(numLiterals int, numOffsets int, litE
303303
w.codegenFreq[size]++
304304
count--
305305
for count >= 3 {
306-
n := 6
307-
if n > count {
308-
n = count
309-
}
306+
n := min(6, count)
310307
codegen[outIndex] = 16
311308
outIndex++
312309
codegen[outIndex] = uint8(n - 3)
@@ -316,10 +313,7 @@ func (w *huffmanBitWriter) generateCodegen(numLiterals int, numOffsets int, litE
316313
}
317314
} else {
318315
for count >= 11 {
319-
n := 138
320-
if n > count {
321-
n = count
322-
}
316+
n := min(138, count)
323317
codegen[outIndex] = 18
324318
outIndex++
325319
codegen[outIndex] = uint8(n - 11)
@@ -472,7 +466,7 @@ func (w *huffmanBitWriter) writeDynamicHeader(numLiterals int, numOffsets int, n
472466
w.writeBits(int32(numOffsets-1), 5)
473467
w.writeBits(int32(numCodegens-4), 4)
474468

475-
for i := 0; i < numCodegens; i++ {
469+
for i := range numCodegens {
476470
value := uint(w.codegenEncoding.codes[codegenOrder[i]].len())
477471
w.writeBits(int32(value), 3)
478472
}

flate/huffman_code.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ func generateFixedLiteralEncoding() *huffmanEncoder {
9191
h := newHuffmanEncoder(literalCount)
9292
codes := h.codes
9393
var ch uint16
94-
for ch = 0; ch < literalCount; ch++ {
94+
for ch = range uint16(literalCount) {
9595
var bits uint16
9696
var size uint8
9797
switch {

flate/inflate.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -485,7 +485,7 @@ func (f *decompressor) readHuffman() error {
485485
f.nb -= 5 + 5 + 4
486486

487487
// (HCLEN+4)*3 bits: code lengths in the magic codeOrder order.
488-
for i := 0; i < nclen; i++ {
488+
for i := range nclen {
489489
for f.nb < 3 {
490490
if err := f.moreBits(); err != nil {
491491
return err
@@ -776,7 +776,7 @@ func fixedHuffmanDecoderInit() {
776776
fixedOnce.Do(func() {
777777
// These come from the RFC section 3.2.6.
778778
var bits [288]int
779-
for i := 0; i < 144; i++ {
779+
for i := range 144 {
780780
bits[i] = 8
781781
}
782782
for i := 144; i < 256; i++ {

flate/level5.go

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -677,10 +677,7 @@ func (e *fastEncL5Window) matchlen(s, t int32, src []byte) int32 {
677677
panic(fmt.Sprint(s, "-", t, "(", s-t, ") > maxMatchLength (", maxMatchOffset, ")"))
678678
}
679679
}
680-
s1 := int(s) + maxMatchLength - 4
681-
if s1 > len(src) {
682-
s1 = len(src)
683-
}
680+
s1 := min(int(s)+maxMatchLength-4, len(src))
684681

685682
// Extend the match to be as long as possible.
686683
return int32(matchLen(src[s:s1], src[t:]))

0 commit comments

Comments
 (0)