[gnome-shell] status/network: Make connectivity queue a Set



commit de175dfca4a01346600cbd4bc2cce7b898777011
Author: Florian Müllner <fmuellner gnome org>
Date:   Mon Aug 1 01:17:53 2022 +0200

    status/network: Make connectivity queue a Set
    
    It's better suited than an array.
    
    Part-of: <https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/2406>

 js/ui/status/network.js | 29 +++++++++--------------------
 1 file changed, 9 insertions(+), 20 deletions(-)
---
diff --git a/js/ui/status/network.js b/js/ui/status/network.js
index 0ae423b682..d2802f328e 100644
--- a/js/ui/status/network.js
+++ b/js/ui/status/network.js
@@ -1759,7 +1759,7 @@ class Indicator extends PanelMenu.SystemIndicator {
 
         this._activeConnections = [];
         this._connections = [];
-        this._connectivityQueue = [];
+        this._connectivityQueue = new Set();
 
         this._mainConnection = null;
 
@@ -2090,23 +2090,14 @@ class Indicator extends PanelMenu.SystemIndicator {
     }
 
     _flushConnectivityQueue() {
-        if (this._portalHelperProxy) {
-            for (let item of this._connectivityQueue)
-                this._portalHelperProxy.CloseAsync(item).catch(logError);
-        }
-
-        this._connectivityQueue = [];
+        for (let item of this._connectivityQueue)
+            this._portalHelperProxy?.CloseAsync(item);
+        this._connectivityQueue.clear();
     }
 
     _closeConnectivityCheck(path) {
-        let index = this._connectivityQueue.indexOf(path);
-
-        if (index >= 0) {
-            if (this._portalHelperProxy)
-                this._portalHelperProxy.CloseAsync(path).catch(logError);
-
-            this._connectivityQueue.splice(index, 1);
-        }
+        if (this._connectivityQueue.delete(path))
+            this._portalHelperProxy?.CloseAsync(path);
     }
 
     async _portalHelperDone(proxy, emitter, parameters) {
@@ -2149,10 +2140,8 @@ class Indicator extends PanelMenu.SystemIndicator {
             return;
 
         let path = this._mainConnection.get_path();
-        for (let item of this._connectivityQueue) {
-            if (item == path)
-                return;
-        }
+        if (this._connectivityQueue.has(path))
+            return;
 
         let timestamp = global.get_current_time();
         if (!this._portalHelperProxy) {
@@ -2176,7 +2165,7 @@ class Indicator extends PanelMenu.SystemIndicator {
 
         this._portalHelperProxy?.AuthenticateAsync(path, '', timestamp).catch(logError);
 
-        this._connectivityQueue.push(path);
+        this._connectivityQueue.add(path);
     }
 
     _updateIcon() {


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]