Skip to content

Commit 038c5f3

Browse files
committed
cli/compose/convert: convertUlimits: modernize
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
1 parent 7b93d61 commit 038c5f3

1 file changed

Lines changed: 14 additions & 18 deletions

File tree

cli/compose/convert/service.go

Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
package convert
22

33
import (
4+
"cmp"
45
"context"
56
"errors"
67
"fmt"
78
"net/netip"
89
"os"
10+
"slices"
911
"sort"
1012
"strings"
1113
"time"
@@ -702,28 +704,22 @@ func convertCredentialSpec(namespace Namespace, spec composetypes.CredentialSpec
702704
}
703705

704706
func convertUlimits(origUlimits map[string]*composetypes.UlimitsConfig) []*container.Ulimit {
705-
newUlimits := make(map[string]*container.Ulimit)
707+
ulimits := make([]*container.Ulimit, 0, len(origUlimits))
706708
for name, u := range origUlimits {
709+
soft, hard := int64(u.Soft), int64(u.Hard)
707710
if u.Single != 0 {
708-
newUlimits[name] = &container.Ulimit{
709-
Name: name,
710-
Soft: int64(u.Single),
711-
Hard: int64(u.Single),
712-
}
713-
} else {
714-
newUlimits[name] = &container.Ulimit{
715-
Name: name,
716-
Soft: int64(u.Soft),
717-
Hard: int64(u.Hard),
718-
}
711+
soft, hard = int64(u.Single), int64(u.Single)
719712
}
713+
714+
ulimits = append(ulimits, &container.Ulimit{
715+
Name: name,
716+
Soft: soft,
717+
Hard: hard,
718+
})
720719
}
721-
ulimits := make([]*container.Ulimit, 0, len(newUlimits))
722-
for _, ulimit := range newUlimits {
723-
ulimits = append(ulimits, ulimit)
724-
}
725-
sort.SliceStable(ulimits, func(i, j int) bool {
726-
return ulimits[i].Name < ulimits[j].Name
720+
721+
slices.SortFunc(ulimits, func(a, b *container.Ulimit) int {
722+
return cmp.Compare(a.Name, b.Name)
727723
})
728724
return ulimits
729725
}

0 commit comments

Comments
 (0)