refactor: remove redundant map lookups in browser/api/menu.ts (#48732)

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

Co-authored-by: trop[bot] <37223003+trop[bot]@users.noreply.github.com>
Co-authored-by: Charles Kerr <charles@charleskerr.com>
This commit is contained in:
trop[bot]
2025-10-30 09:43:25 -04:00
committed by GitHub
parent 3c8714a940
commit 2b99c7645d

View File

@@ -46,11 +46,11 @@ Menu.prototype._isCommandIdEnabled = 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) {
return this.commandsMap[id] ? this.commandsMap[id].visible : false;
return this.commandsMap[id]?.visible ?? false;
};
Menu.prototype._getAcceleratorForCommandId = function (id, useDefaultAccelerator) {
@@ -61,12 +61,12 @@ Menu.prototype._getAcceleratorForCommandId = function (id, useDefaultAccelerator
};
Menu.prototype._shouldRegisterAcceleratorForCommandId = function (id) {
return this.commandsMap[id] ? this.commandsMap[id].registerAccelerator : false;
return this.commandsMap[id]?.registerAccelerator ?? false;
};
if (process.platform === 'darwin') {
Menu.prototype._getSharingItemForCommandId = function (id) {
return this.commandsMap[id] ? this.commandsMap[id].sharingItem : null;
return this.commandsMap[id]?.sharingItem ?? null;
};
}