nmcli: use Map-based lookups for network deduplication
Replace O(n²) nested .filter()/.find() loops with Map-keyed lookups for both removal and update passes in getNetworks().
This commit is contained in:
parent
11f5a2ee45
commit
9464c72f7a
1 changed files with 16 additions and 8 deletions
|
|
@ -751,17 +751,25 @@ Singleton {
|
||||||
const networks = deduplicateNetworks(allNetworks);
|
const networks = deduplicateNetworks(allNetworks);
|
||||||
const rNetworks = root.networks;
|
const rNetworks = root.networks;
|
||||||
|
|
||||||
const destroyed = rNetworks.filter(rn => !networks.find(n => n.frequency === rn.frequency && n.ssid === rn.ssid && n.bssid === rn.bssid));
|
const newMap = new Map();
|
||||||
for (const network of destroyed) {
|
for (const n of networks)
|
||||||
const index = rNetworks.indexOf(network);
|
newMap.set(`${n.frequency}:${n.ssid}:${n.bssid}`, n);
|
||||||
if (index >= 0) {
|
|
||||||
rNetworks.splice(index, 1);
|
for (let i = rNetworks.length - 1; i >= 0; i--) {
|
||||||
network.destroy();
|
const rn = rNetworks[i];
|
||||||
|
const key = `${rn.frequency}:${rn.ssid}:${rn.bssid}`;
|
||||||
|
if (!newMap.has(key)) {
|
||||||
|
rNetworks.splice(i, 1);
|
||||||
|
rn.destroy();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (const network of networks) {
|
const existingMap = new Map();
|
||||||
const match = rNetworks.find(n => n.frequency === network.frequency && n.ssid === network.ssid && n.bssid === network.bssid);
|
for (const rn of rNetworks)
|
||||||
|
existingMap.set(`${rn.frequency}:${rn.ssid}:${rn.bssid}`, rn);
|
||||||
|
|
||||||
|
for (const [key, network] of newMap) {
|
||||||
|
const match = existingMap.get(key);
|
||||||
if (match) {
|
if (match) {
|
||||||
match.lastIpcObject = network;
|
match.lastIpcObject = network;
|
||||||
} else {
|
} else {
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue