[gnome-shell] signalTracker: Avoid doing two maps lookups once they're initialized
- From: Marge Bot <marge-bot src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-shell] signalTracker: Avoid doing two maps lookups once they're initialized
- Date: Wed, 6 Jul 2022 17:12:32 +0000 (UTC)
commit 68ceed5c281a8931a1c45f170361a471312d0666
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>
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 e7a14910df..30d19a27f6 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]