mirror of
https://github.com/electron/electron.git
synced 2026-01-09 15:38:08 -05:00
refactor: remove redundant map lookups in browser/api/menu.ts (#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
This commit is contained in:
@@ -46,11 +46,11 @@ Menu.prototype._isCommandIdEnabled = function (id) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
Menu.prototype._shouldCommandIdWorkWhenHidden = function (id) {
|
Menu.prototype._shouldCommandIdWorkWhenHidden = function (id) {
|
||||||
return this.commandsMap[id] ? !!this.commandsMap[id].acceleratorWorksWhenHidden : false;
|
return this.commandsMap[id]?.acceleratorWorksWhenHidden ?? false;
|
||||||
};
|
};
|
||||||
|
|
||||||
Menu.prototype._isCommandIdVisible = function (id) {
|
Menu.prototype._isCommandIdVisible = function (id) {
|
||||||
return this.commandsMap[id] ? this.commandsMap[id].visible : false;
|
return this.commandsMap[id]?.visible ?? false;
|
||||||
};
|
};
|
||||||
|
|
||||||
Menu.prototype._getAcceleratorForCommandId = function (id, useDefaultAccelerator) {
|
Menu.prototype._getAcceleratorForCommandId = function (id, useDefaultAccelerator) {
|
||||||
@@ -61,12 +61,12 @@ Menu.prototype._getAcceleratorForCommandId = function (id, useDefaultAccelerator
|
|||||||
};
|
};
|
||||||
|
|
||||||
Menu.prototype._shouldRegisterAcceleratorForCommandId = function (id) {
|
Menu.prototype._shouldRegisterAcceleratorForCommandId = function (id) {
|
||||||
return this.commandsMap[id] ? this.commandsMap[id].registerAccelerator : false;
|
return this.commandsMap[id]?.registerAccelerator ?? false;
|
||||||
};
|
};
|
||||||
|
|
||||||
if (process.platform === 'darwin') {
|
if (process.platform === 'darwin') {
|
||||||
Menu.prototype._getSharingItemForCommandId = function (id) {
|
Menu.prototype._getSharingItemForCommandId = function (id) {
|
||||||
return this.commandsMap[id] ? this.commandsMap[id].sharingItem : null;
|
return this.commandsMap[id]?.sharingItem ?? null;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user