From cd2d361d63bbde460bbdd33fa4cfefa6b257b742 Mon Sep 17 00:00:00 2001 From: Benjamin Pasero Date: Thu, 2 May 2024 12:49:59 +0200 Subject: [PATCH] perf - reduce startup allocations --- src/vs/platform/actions/common/menuService.ts | 8 ++++---- src/vs/workbench/common/contextkeys.ts | 3 +-- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/src/vs/platform/actions/common/menuService.ts b/src/vs/platform/actions/common/menuService.ts index 5442fff3a7c..61fefa8e4ae 100644 --- a/src/vs/platform/actions/common/menuService.ts +++ b/src/vs/platform/actions/common/menuService.ts @@ -237,7 +237,7 @@ class MenuInfo { for (const group of this._menuGroups) { const [id, items] = group; - const activeActions: Array = []; + let activeActions: Array | undefined; for (const item of items) { if (this._contextKeyService.contextMatchesRules(item.when)) { const isMenuItem = isIMenuItem(item); @@ -249,18 +249,18 @@ class MenuInfo { if (isMenuItem) { // MenuItemAction const menuKeybinding = createConfigureKeybindingAction(item.command.id, item.when, this._commandService, this._keybindingService); - activeActions.push(new MenuItemAction(item.command, item.alt, options, menuHide, menuKeybinding, this._contextKeyService, this._commandService)); + (activeActions ??= []).push(new MenuItemAction(item.command, item.alt, options, menuHide, menuKeybinding, this._contextKeyService, this._commandService)); } else { // SubmenuItemAction const groups = new MenuInfo(item.submenu, this._hiddenStates, this._collectContextKeysForSubmenus, this._commandService, this._keybindingService, this._contextKeyService).createActionGroups(options); const submenuActions = Separator.join(...groups.map(g => g[1])); if (submenuActions.length > 0) { - activeActions.push(new SubmenuItemAction(item, menuHide, submenuActions)); + (activeActions ??= []).push(new SubmenuItemAction(item, menuHide, submenuActions)); } } } } - if (activeActions.length > 0) { + if (activeActions && activeActions.length > 0) { result.push([id, activeActions]); } } diff --git a/src/vs/workbench/common/contextkeys.ts b/src/vs/workbench/common/contextkeys.ts index 612f006a88c..1c82f8542c8 100644 --- a/src/vs/workbench/common/contextkeys.ts +++ b/src/vs/workbench/common/contextkeys.ts @@ -292,13 +292,12 @@ export function applyAvailableEditorIds(contextKey: IContextKey, editor: } const editorResource = editor.resource; - const editors = editorResource ? editorResolverService.getEditors(editorResource).map(editor => editor.id) : []; - if (editorResource?.scheme === Schemas.untitled && editor.editorId !== DEFAULT_EDITOR_ASSOCIATION.id) { // Non text editor untitled files cannot be easily serialized between extensions // so instead we disable this context key to prevent common commands that act on the active editor contextKey.set(''); } else { + const editors = editorResource ? editorResolverService.getEditors(editorResource).map(editor => editor.id) : []; contextKey.set(editors.join(',')); } }