Skip to content

Commit 0484738

Browse files
committed
nat: portMapSorter: slight optimization
- Skip ParsePortRange as intermediate (as we don't need an uint64) - Use strings.Equalfold, which doesn't allocate. Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
1 parent fa986a4 commit 0484738

1 file changed

Lines changed: 3 additions & 3 deletions

File tree

nat/sort.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ func (s portMapSorter) Swap(i, j int) { s[i], s[j] = s[j], s[i] }
5050
func (s portMapSorter) Less(i, j int) bool {
5151
pi, pj := s[i].port, s[j].port
5252
hpi, hpj := toInt(s[i].binding.HostPort), toInt(s[j].binding.HostPort)
53-
return hpi > hpj || pi.Int() > pj.Int() || (pi.Int() == pj.Int() && strings.ToLower(pi.Proto()) == "tcp")
53+
return hpi > hpj || pi.Int() > pj.Int() || (pi.Int() == pj.Int() && strings.EqualFold(pi.Proto(), "tcp"))
5454
}
5555

5656
// SortPortMap sorts the list of ports and their respected mapping. The ports
@@ -87,8 +87,8 @@ func SortPortMap(ports []Port, bindings map[Port][]PortBinding) {
8787
}
8888
}
8989

90-
func toInt(s string) uint64 {
91-
i, _, err := ParsePortRange(s)
90+
func toInt(s string) int {
91+
i, _, err := parsePortRange(s)
9292
if err != nil {
9393
i = 0
9494
}

0 commit comments

Comments
 (0)