Skip to content

Commit

Permalink
go/cache: use new range for loop
Browse files Browse the repository at this point in the history
Signed-off-by: Andrew Mason <andrew@planetscale.com>
  • Loading branch information
Andrew Mason committed Feb 15, 2024
1 parent 34fa3ad commit d2703e3
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 7 deletions.
2 changes: 1 addition & 1 deletion go/cache/theine/sketch_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ func TestSketch(t *testing.T) {
sketch.SampleSize = 5120

failed := 0
for i := 0; i < 500; i++ {
for i := range 500 {
key := fmt.Sprintf("key:%d", i)
keyh := xxhash.Sum64String(key)
sketch.Add(keyh)
Expand Down
2 changes: 1 addition & 1 deletion go/cache/theine/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ func NewStore[K cachekey, V cacheval](maxsize int64, doorkeeper bool) *Store[K,
writebufsize: writeBufSize,
}
s.shards = make([]*Shard[K, V], 0, s.shardCount)
for i := 0; i < int(s.shardCount); i++ {
for range s.shardCount {
s.shards = append(s.shards, NewShard[K, V](uint(dequeSize), doorkeeper))
}

Expand Down
4 changes: 2 additions & 2 deletions go/cache/theine/store_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ func TestProcessDeque(t *testing.T) {
shard := store.shards[index]
shard.qsize = 10

for i := keyint(0); i < 5; i++ {
for i := range keyint(5) {
entry := &Entry[keyint, cachedint]{key: i}
entry.cost.Store(1)
store.shards[index].deque.PushFront(entry)
Expand All @@ -75,7 +75,7 @@ func TestDoorKeeperDynamicSize(t *testing.T) {
store := NewStore[keyint, cachedint](200000, true)
shard := store.shards[0]
require.True(t, shard.doorkeeper.Capacity == 512)
for i := keyint(0); i < 5000; i++ {
for i := range keyint(5000) {
shard.set(i, &Entry[keyint, cachedint]{})
}
require.True(t, shard.doorkeeper.Capacity > 100000)
Expand Down
6 changes: 3 additions & 3 deletions go/cache/theine/tlfu_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ func TestTlfu(t *testing.T) {
require.Equal(t, 0, tlfu.slru.protected.len)

var entries []*Entry[StringKey, string]
for i := 0; i < 200; i++ {
for i := range 200 {
e := NewEntry(StringKey(fmt.Sprintf("%d", i)), "", 1)
evicted := tlfu.Set(e)
entries = append(entries, e)
Expand Down Expand Up @@ -78,7 +78,7 @@ func TestTlfu(t *testing.T) {
require.Equal(t, 998, tlfu.slru.probation.len)

var entries2 []*Entry[StringKey, string]
for i := 0; i < 1000; i++ {
for i := range 1000 {
e := NewEntry(StringKey(fmt.Sprintf("%d*", i)), "", 1)
tlfu.Set(e)
entries2 = append(entries2, e)
Expand All @@ -103,7 +103,7 @@ func TestEvictEntries(t *testing.T) {
require.Equal(t, 0, tlfu.slru.probation.len)
require.Equal(t, 0, tlfu.slru.protected.len)

for i := 0; i < 500; i++ {
for i := range 500 {
tlfu.Set(NewEntry(StringKey(fmt.Sprintf("%d:1", i)), "", 1))
}
require.Equal(t, 500, tlfu.slru.probation.len)
Expand Down

0 comments on commit d2703e3

Please sign in to comment.