[gnome-shell/gnome-42] signalTracker: Avoid doing two maps lookups once they're initialized



commit b4828b4fdddda7d4247c20ffc7b5c8e1b85cb0ca
Author: Marco Trevisan (Treviño) <mail 3v1n0 net>
Date:   Wed Jul 6 17:44:48 2022 +0200

    signalTracker: Avoid doing two maps lookups once they're initialized
    
    Avoid checking if a map contains a value, given that in the case it's
    not there, get() will just return an undefined value. And only in such
    case we need to set the value.
    
    Part-of: <https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/2366>
    (cherry picked from commit 68ceed5c281a8931a1c45f170361a471312d0666)

 js/misc/signalTracker.js | 18 ++++++++++++------
 1 file changed, 12 insertions(+), 6 deletions(-)
---
diff --git a/js/misc/signalTracker.js b/js/misc/signalTracker.js
index bcfa72de97..a214291420 100644
--- a/js/misc/signalTracker.js
+++ b/js/misc/signalTracker.js
@@ -50,9 +50,12 @@ class SignalManager {
      * @returns {SignalTracker} - the signal tracker for object
      */
     getSignalTracker(obj) {
-        if (!this._signalTrackers.has(obj))
-            this._signalTrackers.set(obj, new SignalTracker(obj));
-        return this._signalTrackers.get(obj);
+        let signalTracker = this._signalTrackers.get(obj);
+        if (signalTracker === undefined) {
+            signalTracker = new SignalTracker(obj);
+            this._signalTrackers.set(obj, signalTracker);
+        }
+        return signalTracker;
     }
 }
 
@@ -80,9 +83,12 @@ class SignalTracker {
      * @returns {SignalData} - signal data for object
      */
     _getSignalData(obj) {
-        if (!this._map.has(obj))
-            this._map.set(obj, { ownerSignals: [], destroyId: 0 });
-        return this._map.get(obj);
+        let data = this._map.get(obj);
+        if (data === undefined) {
+            data = { ownerSignals: [], destroyId: 0 };
+            this._map.set(obj, data);
+        }
+        return data;
     }
 
     /**


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