|
| 1 | +// FIXME(thaJeztah): remove once we are a module; the go:build directive prevents go from downgrading language version to go1.16: |
| 2 | +//go:build go1.24 |
| 3 | + |
1 | 4 | package convert |
2 | 5 |
|
3 | 6 | import ( |
| 7 | + "cmp" |
4 | 8 | "context" |
5 | 9 | "errors" |
6 | 10 | "fmt" |
7 | 11 | "net/netip" |
8 | 12 | "os" |
| 13 | + "slices" |
9 | 14 | "sort" |
10 | 15 | "strings" |
11 | 16 | "time" |
@@ -702,28 +707,22 @@ func convertCredentialSpec(namespace Namespace, spec composetypes.CredentialSpec |
702 | 707 | } |
703 | 708 |
|
704 | 709 | func convertUlimits(origUlimits map[string]*composetypes.UlimitsConfig) []*container.Ulimit { |
705 | | - newUlimits := make(map[string]*container.Ulimit) |
| 710 | + ulimits := make([]*container.Ulimit, 0, len(origUlimits)) |
706 | 711 | for name, u := range origUlimits { |
| 712 | + soft, hard := int64(u.Soft), int64(u.Hard) |
707 | 713 | 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 | | - } |
| 714 | + soft, hard = int64(u.Single), int64(u.Single) |
719 | 715 | } |
| 716 | + |
| 717 | + ulimits = append(ulimits, &container.Ulimit{ |
| 718 | + Name: name, |
| 719 | + Soft: soft, |
| 720 | + Hard: hard, |
| 721 | + }) |
720 | 722 | } |
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 |
| 723 | + |
| 724 | + slices.SortFunc(ulimits, func(a, b *container.Ulimit) int { |
| 725 | + return cmp.Compare(a.Name, b.Name) |
727 | 726 | }) |
728 | 727 | return ulimits |
729 | 728 | } |
0 commit comments