Skip to content

Commit

Permalink
perf - reduce startup allocations
Browse files Browse the repository at this point in the history
  • Loading branch information
bpasero committed May 2, 2024
1 parent 03dd3c3 commit 0d7778d
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 6 deletions.
8 changes: 4 additions & 4 deletions src/vs/platform/actions/common/menuService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ class MenuInfo {
for (const group of this._menuGroups) {
const [id, items] = group;

const activeActions: Array<MenuItemAction | SubmenuItemAction> = [];
let activeActions: Array<MenuItemAction | SubmenuItemAction> | undefined;
for (const item of items) {
if (this._contextKeyService.contextMatchesRules(item.when)) {
const isMenuItem = isIMenuItem(item);
Expand All @@ -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]);
}
}
Expand Down
3 changes: 1 addition & 2 deletions src/vs/workbench/common/contextkeys.ts
Original file line number Diff line number Diff line change
Expand Up @@ -292,13 +292,12 @@ export function applyAvailableEditorIds(contextKey: IContextKey<string>, 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(','));
}
}

0 comments on commit 0d7778d

Please sign in to comment.