mirror of
https://github.com/netbirdio/ice.git
synced 2026-05-22 17:10:58 -07: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:
+4
-3
@@ -95,12 +95,13 @@ func NewUDPMuxDefault(params UDPMuxParams) *UDPMuxDefault { //nolint:cyclop
|
||||
|
||||
_, addrs, err := localInterfaces(params.Net, nil, nil, networks, true)
|
||||
if err == nil {
|
||||
for _, addr := range addrs {
|
||||
localAddrsForUnspecified = append(localAddrsForUnspecified, &net.UDPAddr{
|
||||
localAddrsForUnspecified = make([]net.Addr, len(addrs))
|
||||
for i, addr := range addrs {
|
||||
localAddrsForUnspecified[i] = &net.UDPAddr{
|
||||
IP: addr.AsSlice(),
|
||||
Port: udpAddr.Port,
|
||||
Zone: addr.Zone(),
|
||||
})
|
||||
}
|
||||
}
|
||||
} else {
|
||||
params.Logger.Errorf("Failed to get local interfaces for unspecified addr: %v", err)
|
||||
|
||||
Reference in New Issue
Block a user