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)
|
||||
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