Skip to content

Commit 51e0d9d

Browse files
committed
refactor: remove redundant map lookups in browser/api/menu.ts (electron#48706)
perf: avoid double map lookup in Menu.prototype._shouldCommandIdWorkWhenHidden perf: avoid double map lookup in Menu.prototype._isCommandIdVisible perf: avoid double map lookup in Menu.prototype._shouldRegisterAcceleratorForCommandId perf: avoid double map lookup in Menu.prototype._getSharingItemForCommandId
1 parent 7a87603 commit 51e0d9d

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

lib/browser/api/menu.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,11 @@ Menu.prototype._isCommandIdEnabled = function (id) {
4646
};
4747

4848
Menu.prototype._shouldCommandIdWorkWhenHidden = function (id) {
49-
return this.commandsMap[id] ? !!this.commandsMap[id].acceleratorWorksWhenHidden : false;
49+
return this.commandsMap[id]?.acceleratorWorksWhenHidden ?? false;
5050
};
5151

5252
Menu.prototype._isCommandIdVisible = function (id) {
53-
return this.commandsMap[id] ? this.commandsMap[id].visible : false;
53+
return this.commandsMap[id]?.visible ?? false;
5454
};
5555

5656
Menu.prototype._getAcceleratorForCommandId = function (id, useDefaultAccelerator) {
@@ -61,12 +61,12 @@ Menu.prototype._getAcceleratorForCommandId = function (id, useDefaultAccelerator
6161
};
6262

6363
Menu.prototype._shouldRegisterAcceleratorForCommandId = function (id) {
64-
return this.commandsMap[id] ? this.commandsMap[id].registerAccelerator : false;
64+
return this.commandsMap[id]?.registerAccelerator ?? false;
6565
};
6666

6767
if (process.platform === 'darwin') {
6868
Menu.prototype._getSharingItemForCommandId = function (id) {
69-
return this.commandsMap[id] ? this.commandsMap[id].sharingItem : null;
69+
return this.commandsMap[id]?.sharingItem ?? null;
7070
};
7171
}
7272

0 commit comments

Comments
 (0)