Skip to content

Commit a473597

Browse files
committed
Use for range with integers
This form is available since Go 1.22. Signed-off-by: Kir Kolyshkin <[email protected]>
1 parent cfe7b24 commit a473597

File tree

6 files changed

+6
-6
lines changed

6 files changed

+6
-6
lines changed

devices/systemd_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ func TestPodSkipDevicesUpdate(t *testing.T) {
9595
}
9696

9797
// Now update the pod a few times.
98-
for i := 0; i < 42; i++ {
98+
for range 42 {
9999
podConfig.Resources.PidsLimit++
100100
podConfig.Resources.Memory += 1024 * 1024
101101
if err := pm.Set(podConfig.Resources); err != nil {

file_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ func TestWriteCgroupFileHandlesInterrupt(t *testing.T) {
3232
t.Skip(err)
3333
}
3434

35-
for i := 0; i < 100000; i++ {
35+
for i := range 100000 {
3636
limit := 1024*1024 + i
3737
if err := WriteFile(cgroupPath, memoryLimit, strconv.Itoa(limit)); err != nil {
3838
t.Fatalf("Failed to write %d on attempt %d: %+v", limit, i, err)

fs/freezer.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ func (s *FreezerGroup) Set(path string, r *cgroups.Resources) (Err error) {
5757
// Alas, this is still a game of chances, since the real fix
5858
// belong to the kernel (cgroup v2 do not have this bug).
5959

60-
for i := 0; i < 1000; i++ {
60+
for i := range 1000 {
6161
if i%50 == 49 {
6262
// Occasional thaw and sleep improves
6363
// the chances to succeed in freezing

systemd/common.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,7 @@ func systemdVersionAtoi(str string) (int, error) {
266266
// Unconditionally remove the leading prefix ("v).
267267
str = strings.TrimLeft(str, `"v`)
268268
// Match on the first integer we can grab.
269-
for i := 0; i < len(str); i++ {
269+
for i := range len(str) {
270270
if str[i] < '0' || str[i] > '9' {
271271
// First non-digit: cut the tail.
272272
str = str[:i]

systemd/systemd_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ func TestUnitExistsIgnored(t *testing.T) {
9090
pm := newManager(t, podConfig)
9191

9292
// create twice to make sure "UnitExists" error is ignored.
93-
for i := 0; i < 2; i++ {
93+
for range 2 {
9494
if err := pm.Apply(-1); err != nil {
9595
t.Fatal(err)
9696
}

utils.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -395,7 +395,7 @@ func WriteCgroupProc(dir string, pid int) error {
395395
}
396396
defer file.Close()
397397

398-
for i := 0; i < 5; i++ {
398+
for range 5 {
399399
_, err = file.WriteString(strconv.Itoa(pid))
400400
if err == nil {
401401
return nil

0 commit comments

Comments
 (0)