Skip to content

Commit 5a48a5c

Browse files
authored
refactor: apply go fix modernizers from Go 1.26 (#246)
This PR applies automated refactoring from go 1.26 (go fix ./...): - interface{} to any, slices.Contains, range loops and other idiomatic updates.
1 parent 2c423b6 commit 5a48a5c

File tree

5 files changed

+9
-15
lines changed

5 files changed

+9
-15
lines changed

cache/radixcache/radixcache_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,7 @@ func TestUnboundedGrowth(t *testing.T) {
273273

274274
s = New(maxSize)
275275

276-
for i := 0; i < maxSize; i++ {
276+
for i := range maxSize {
277277
value.ContextID = []byte(mhs[i])
278278
s.Put(value, mhash)
279279
s.Remove(value, mhash)
@@ -556,7 +556,7 @@ func TestMemSingleVsMany(t *testing.T) {
556556

557557
t.Run(fmt.Sprintf("Put %d Single multihashes", 1024*1024), func(t *testing.T) {
558558
s := New(1024 * 1024)
559-
for i := 0; i < 1024; i++ {
559+
for range 1024 {
560560
mhs = random.Multihashes(1024)
561561
for j := range mhs {
562562
s.Put(value, mhs[j])
@@ -570,7 +570,7 @@ func TestMemSingleVsMany(t *testing.T) {
570570

571571
t.Run(fmt.Sprintf("Put %d multihashes in groups of 1024", 1024*1024), func(t *testing.T) {
572572
s := New(1024 * 1024)
573-
for i := 0; i < 1024; i++ {
573+
for range 1024 {
574574
mhs = random.Multihashes(1024)
575575
s.Put(value, mhs...)
576576
}

store/dhstore/dhstore.go

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -123,10 +123,7 @@ func (s *dhStore) Put(value indexer.Value, mhs ...multihash.Multihash) error {
123123
stats.WithTags(tag.Insert(metrics.Method, "put")),
124124
stats.WithMeasurements(metrics.DHMetadataLatency.M(metrics.MsecSince(start))))
125125

126-
size := s.batchSize
127-
if len(mhs) < size {
128-
size = len(mhs)
129-
}
126+
size := min(len(mhs), s.batchSize)
130127
merges := make([]client.Index, 0, size)
131128
for _, mh := range mhs {
132129
if _, err = multihash.Decode(mh); err != nil {
@@ -161,10 +158,7 @@ func (s *dhStore) Put(value indexer.Value, mhs ...multihash.Multihash) error {
161158
func (s *dhStore) Remove(value indexer.Value, mhs ...multihash.Multihash) error {
162159
ctx := context.Background()
163160
valueKey := dhash.CreateValueKey(value.ProviderID, value.ContextID)
164-
size := s.batchSize
165-
if len(mhs) < size {
166-
size = len(mhs)
167-
}
161+
size := min(len(mhs), s.batchSize)
168162
dels := make([]client.Index, 0, size)
169163

170164
for _, mh := range mhs {

store/pebble/codec.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ func (c *codec) unmarshalValueKeys(b []byte) (*keyList, error) {
8181
}
8282
vks := c.p.leaseKeyList()
8383
vks.maybeGrow(vkl)
84-
for i := 0; i < vkl; i++ {
84+
for i := range vkl {
8585
vk := c.p.leaseKey()
8686
offset := marshalledValueKeyLength * i
8787
vk.append(b[offset+1 : offset+marshalledValueKeyLength]...)

store/test/tests.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -632,7 +632,7 @@ func ParallelUpdateTest(t *testing.T, s indexer.Interface) {
632632

633633
// Test parallel writes over same multihash
634634
wg.Add(5)
635-
for i := 0; i < 5; i++ {
635+
for i := range 5 {
636636
i := i
637637
go func() {
638638
t.Log("Put/Get different multihash")
@@ -661,7 +661,7 @@ func ParallelUpdateTest(t *testing.T, s indexer.Interface) {
661661

662662
// Test remove for all except one
663663
wg.Add(4)
664-
for i := 0; i < 4; i++ {
664+
for i := range 4 {
665665
i := i
666666
go func() {
667667
t.Log("Remove multihash")

value_codec_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,7 @@ func TestValueCodec_BinaryWithJsonAlwaysMarshalsAsBinary(t *testing.T) {
239239
func generateRandomValueKeys(count int) [][]byte {
240240
var vks [][]byte
241241
rng := rand.New(rand.NewSource(1413))
242-
for i := 0; i < count; i++ {
242+
for range count {
243243
vk := make([]byte, rng.Intn(127)+1)
244244
vks = append(vks, vk)
245245
}

0 commit comments

Comments
 (0)