daemon/libnetwork/types: remove TransportPort.GetCopy()

The `GetCopy()` function doesn't de-reference anything, as it's
all a straight copy. We can remove it as it's only making things
more complicated than needed.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
Sebastiaan van Stijn
2025-08-10 19:47:45 +02:00
parent 385297ee40
commit 561e14ea3f
4 changed files with 4 additions and 24 deletions

View File

@@ -1399,12 +1399,7 @@ func (d *driver) EndpointOperInfo(nid, eid string) (map[string]any, error) {
m := make(map[string]any)
if ep.extConnConfig != nil && ep.extConnConfig.ExposedPorts != nil {
// Return a copy of the config data
epc := make([]types.TransportPort, 0, len(ep.extConnConfig.ExposedPorts))
for _, tp := range ep.extConnConfig.ExposedPorts {
epc = append(epc, tp.GetCopy())
}
m[netlabel.ExposedPorts] = epc
m[netlabel.ExposedPorts] = slices.Clone(ep.extConnConfig.ExposedPorts)
}
if ep.portMapping != nil {

View File

@@ -128,13 +128,7 @@ func (nw *StubFirewallerNetwork) AddLink(_ context.Context, parentIP, childIP ne
nw.Links = append(nw.Links, stubFirewallerLink{
parentIP: parentIP,
childIP: childIP,
ports: func() []types.TransportPort {
res := make([]types.TransportPort, 0, len(ports))
for _, p := range ports {
res = append(res, p.GetCopy())
}
return res
}(),
ports: slices.Clone(ports),
})
return nil
}

View File

@@ -17,6 +17,7 @@ import (
"fmt"
"net"
"net/http"
"slices"
"strconv"
"strings"
"sync"
@@ -863,12 +864,7 @@ func (d *driver) EndpointOperInfo(nid, eid string) (map[string]any, error) {
data["hnsid"] = ep.profileID
if ep.epConnectivity.ExposedPorts != nil {
// Return a copy of the config data
epc := make([]types.TransportPort, 0, len(ep.epConnectivity.ExposedPorts))
for _, tp := range ep.epConnectivity.ExposedPorts {
epc = append(epc, tp.GetCopy())
}
data[netlabel.ExposedPorts] = epc
data[netlabel.ExposedPorts] = slices.Clone(ep.epConnectivity.ExposedPorts)
}
if ep.portMapping != nil {

View File

@@ -60,11 +60,6 @@ func (t *TransportPort) Equal(o *TransportPort) bool {
return true
}
// GetCopy returns a copy of this TransportPort structure instance
func (t *TransportPort) GetCopy() TransportPort {
return TransportPort{Proto: t.Proto, Port: t.Port}
}
// String returns the TransportPort structure in string form
func (t *TransportPort) String() string {
return fmt.Sprintf("%s/%d", t.Proto.String(), t.Port)