mirror of
https://github.com/pion/ice.git
synced 2025-09-26 19:41:11 +08:00
Optimize slice allocation in UDPMuxDefault
Pre-allocate localAddrsForUnspecified slice with known capacity and use index assignment instead of append to avoid multiple slice reallocations. Signed-off-by: Xiaobo Liu <cppcoffee@gmail.com>
This commit is contained in:
@@ -95,12 +95,13 @@ func NewUDPMuxDefault(params UDPMuxParams) *UDPMuxDefault { //nolint:cyclop
|
|||||||
|
|
||||||
_, addrs, err := localInterfaces(params.Net, nil, nil, networks, true)
|
_, addrs, err := localInterfaces(params.Net, nil, nil, networks, true)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
for _, addr := range addrs {
|
localAddrsForUnspecified = make([]net.Addr, len(addrs))
|
||||||
localAddrsForUnspecified = append(localAddrsForUnspecified, &net.UDPAddr{
|
for i, addr := range addrs {
|
||||||
|
localAddrsForUnspecified[i] = &net.UDPAddr{
|
||||||
IP: addr.AsSlice(),
|
IP: addr.AsSlice(),
|
||||||
Port: udpAddr.Port,
|
Port: udpAddr.Port,
|
||||||
Zone: addr.Zone(),
|
Zone: addr.Zone(),
|
||||||
})
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
params.Logger.Errorf("Failed to get local interfaces for unspecified addr: %v", err)
|
params.Logger.Errorf("Failed to get local interfaces for unspecified addr: %v", err)
|
||||||
|
Reference in New Issue
Block a user