diff options
| author | 2 * r + 2 * t <61896496+soramanew@users.noreply.github.com> | 2026-03-12 21:51:44 +1100 |
|---|---|---|
| committer | 2 * r + 2 * t <61896496+soramanew@users.noreply.github.com> | 2026-03-12 21:51:44 +1100 |
| commit | 9464c72f7a16154a9cdf1bc95588e07adc4a0870 (patch) | |
| tree | d5790a0a28281db791c00205cc9acc3512566553 | |
| parent | network: debounce nmcli monitor events (diff) | |
| download | caelestia-shell-9464c72f7a16154a9cdf1bc95588e07adc4a0870.tar.gz caelestia-shell-9464c72f7a16154a9cdf1bc95588e07adc4a0870.tar.bz2 caelestia-shell-9464c72f7a16154a9cdf1bc95588e07adc4a0870.zip | |
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().
| -rw-r--r-- | services/Nmcli.qml | 24 |
1 files changed, 16 insertions, 8 deletions
diff --git a/services/Nmcli.qml b/services/Nmcli.qml index 36bd3e6..812387f 100644 --- a/services/Nmcli.qml +++ b/services/Nmcli.qml @@ -751,17 +751,25 @@ Singleton { const networks = deduplicateNetworks(allNetworks); const rNetworks = root.networks; - const destroyed = rNetworks.filter(rn => !networks.find(n => n.frequency === rn.frequency && n.ssid === rn.ssid && n.bssid === rn.bssid)); - for (const network of destroyed) { - const index = rNetworks.indexOf(network); - if (index >= 0) { - rNetworks.splice(index, 1); - network.destroy(); + const newMap = new Map(); + for (const n of networks) + newMap.set(`${n.frequency}:${n.ssid}:${n.bssid}`, n); + + for (let i = rNetworks.length - 1; i >= 0; i--) { + 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 match = rNetworks.find(n => n.frequency === network.frequency && n.ssid === network.ssid && n.bssid === network.bssid); + const existingMap = new Map(); + 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) { match.lastIpcObject = network; } else { |