perf - reduce startup allocations

This commit is contained in:
Benjamin Pasero
2024-05-02 12:49:59 +02:00
committed by Benjamin Pasero
parent 75a7755c65
commit cd2d361d63
2 changed files with 5 additions and 6 deletions
@@ -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);
@@ -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]);
}
}
+1 -2
View File
@@ -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(','));
}
}