From 68ceed5c281a8931a1c45f170361a471312d0666 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marco=20Trevisan=20=28Trevi=C3=B1o=29?= Date: Wed, 6 Jul 2022 17:44:48 +0200 Subject: [PATCH] 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: --- 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 e7a14910d..30d19a27f 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; } /**