Skip to content

Commit bd9228c

Browse files
authored
Apply go fix and check in CI (#1158)
1 parent 4cc176c commit bd9228c

4 files changed

Lines changed: 15 additions & 20 deletions

File tree

‎.github/workflows/go.yml‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,9 @@ jobs:
9090
- name: fmt
9191
run: diff <(gofmt -d .) <(printf "")
9292

93+
- name: fix
94+
run: diff <(go fix -diff ./...) <(printf "")
95+
9396
- name: Test 386
9497
run: GOOS=linux GOARCH=386 go test -short ./...
9598

‎s2/hashtable_pool.go‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,23 +25,23 @@ type betterTables struct {
2525
sTable [betterShortTableSize]uint32
2626
}
2727

28-
var betterTablePool = sync.Pool{New: func() interface{} { return &betterTables{} }}
28+
var betterTablePool = sync.Pool{New: func() any { return &betterTables{} }}
2929

3030
// betterSnappyTables holds better-snappy compression hash tables.
3131
type betterSnappyTables struct {
3232
lTable [betterSnappyLongTableSize]uint32
3333
sTable [betterShortTableSize]uint32
3434
}
3535

36-
var betterSnappyTablePool = sync.Pool{New: func() interface{} { return &betterSnappyTables{} }}
36+
var betterSnappyTablePool = sync.Pool{New: func() any { return &betterSnappyTables{} }}
3737

3838
// bestTables holds best compression hash tables.
3939
type bestTables struct {
4040
lTable [bestLongTableSize]uint64
4141
sTable [bestShortTableSize]uint64
4242
}
4343

44-
var bestTablePool = sync.Pool{New: func() interface{} { return &bestTables{} }}
44+
var bestTablePool = sync.Pool{New: func() any { return &bestTables{} }}
4545

4646
// getBetterTables gets a zeroed betterTables from the pool.
4747
func getBetterTables() *betterTables {

‎zstd/enc_jobs_test.go‎

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -375,7 +375,7 @@ func TestConcurrentBlocks_MultipleFlushes(t *testing.T) {
375375

376376
rng := mrand.New(mrand.NewSource(66))
377377
var want bytes.Buffer
378-
for flush := 0; flush < 5; flush++ {
378+
for flush := range 5 {
379379
chunk := make([]byte, 1<<17)
380380
for i := range chunk {
381381
chunk[i] = byte(rng.Intn(32))
@@ -580,15 +580,10 @@ func TestConcurrentBlocks_WindowSizes(t *testing.T) {
580580
for _, winSize := range testWindowSizes {
581581
t.Run(fmt.Sprintf("w%dk", winSize/1024), func(t *testing.T) {
582582
// Input must exceed jobSize to trigger multi-job.
583-
jobSize := winSize * 4
584-
if jobSize < 512<<10 {
585-
jobSize = 512 << 10
586-
}
587-
inputSize := jobSize*2 + 1000
588-
// Cap at 8MB for test speed.
589-
if inputSize > 8<<20 {
590-
inputSize = 8 << 20
591-
}
583+
jobSize := max(winSize*4, 512<<10)
584+
inputSize := min(
585+
// Cap at 8MB for test speed.
586+
jobSize*2+1000, 8<<20)
592587

593588
input := make([]byte, inputSize)
594589
for i := range input {
@@ -863,7 +858,7 @@ func TestConcurrentBlocks_EncodeAllAlongside(t *testing.T) {
863858

864859
// Concurrent EncodeAll calls.
865860
var encAllWg sync.WaitGroup
866-
for i := 0; i < 20; i++ {
861+
for range 20 {
867862
in := streamInput[rng.Intn(len(streamInput)/2):]
868863
in = in[:rng.Intn(len(in)/4+1)]
869864
encAllWg.Add(1)
@@ -1101,7 +1096,7 @@ func TestConcurrentBlocks_Reset(t *testing.T) {
11011096
}
11021097

11031098
rng := mrand.New(mrand.NewSource(77))
1104-
for i := 0; i < 3; i++ {
1099+
for i := range 3 {
11051100
var buf bytes.Buffer
11061101
enc.Reset(&buf)
11071102

@@ -1258,7 +1253,7 @@ func TestConcurrentBlocks_ManySmallWrites(t *testing.T) {
12581253
rng := mrand.New(mrand.NewSource(33))
12591254
var want bytes.Buffer
12601255
chunk := make([]byte, 1024)
1261-
for i := 0; i < 8192; i++ {
1256+
for range 8192 {
12621257
for j := range chunk {
12631258
chunk[j] = byte(rng.Intn(32))
12641259
}

‎zstd/encoder_options.go‎

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -354,10 +354,7 @@ func WithConcurrentBlocks(b bool) EOption {
354354

355355
// jobSize returns the input section size per parallel job.
356356
func (o *encoderOptions) jobSize() int {
357-
s := o.windowSize * 4
358-
if s < 512<<10 {
359-
s = 512 << 10
360-
}
357+
s := max(o.windowSize*4, 512<<10)
361358
return s
362359
}
363360

0 commit comments

Comments
 (0)