From 683d774ed0fcfb00331c8c865f9f5dc2f5db2c59 Mon Sep 17 00:00:00 2001 From: isidor Date: Thu, 6 Jun 2019 11:21:06 +0200 Subject: [PATCH] loaded scripts: use Map #74948 --- .../debug/browser/loadedScriptsView.ts | 35 ++++++++++--------- 1 file changed, 18 insertions(+), 17 deletions(-) diff --git a/src/vs/workbench/contrib/debug/browser/loadedScriptsView.ts b/src/vs/workbench/contrib/debug/browser/loadedScriptsView.ts index 3a4c68f4bfc..44b5cd46953 100644 --- a/src/vs/workbench/contrib/debug/browser/loadedScriptsView.ts +++ b/src/vs/workbench/contrib/debug/browser/loadedScriptsView.ts @@ -45,16 +45,15 @@ type LoadedScriptsItem = BaseTreeItem; class BaseTreeItem { private _showedMoreThanOne: boolean; - private _children: { [key: string]: BaseTreeItem; }; + private _children = new Map(); private _source: Source; constructor(private _parent: BaseTreeItem | undefined, private _label: string) { - this._children = {}; this._showedMoreThanOne = false; } isLeaf(): boolean { - return Object.keys(this._children).length === 0; + return this._children.size === 0; } getSession(): IDebugSession | undefined { @@ -66,12 +65,12 @@ class BaseTreeItem { setSource(session: IDebugSession, source: Source): void { this._source = source; - this._children = {}; + this._children.clear(); if (source.raw && source.raw.sources) { for (const src of source.raw.sources) { if (src.name && src.path) { const s = new BaseTreeItem(this, src.name); - this._children[src.path] = s; + this._children.set(src.path, s); const ss = session.getSource(src); s.setSource(session, ss); } @@ -80,26 +79,26 @@ class BaseTreeItem { } createIfNeeded(key: string, factory: (parent: BaseTreeItem, label: string) => T): T { - let child = this._children[key]; + let child = this._children.get(key); if (!child) { child = factory(this, key); - this._children[key] = child; + this._children.set(key, child); } return child; } - getChild(key: string): BaseTreeItem { - return this._children[key]; + getChild(key: string): BaseTreeItem | undefined { + return this._children.get(key); } remove(key: string): void { - delete this._children[key]; + this._children.delete(key); } removeFromParent(): void { if (this._parent) { this._parent.remove(this._label); - if (Object.keys(this._parent._children).length === 0) { + if (this._parent._children.size === 0) { this._parent.removeFromParent(); } } @@ -142,7 +141,7 @@ class BaseTreeItem { if (child) { return child.hasChildren(); } - return Object.keys(this._children).length > 0; + return this._children.size > 0; } // skips intermediate single-child nodes @@ -151,7 +150,10 @@ class BaseTreeItem { if (child) { return child.getChildren(); } - const array = Object.keys(this._children).map(key => this._children[key]); + const array = []; + for (let child of this._children.values()) { + array.push(child); + } return Promise.resolve(array.sort((a, b) => this.compare(a, b))); } @@ -199,12 +201,11 @@ class BaseTreeItem { private oneChild(): BaseTreeItem | undefined { if (SMART && !this._source && !this._showedMoreThanOne && !(this instanceof RootFolderTreeItem) && !(this instanceof SessionTreeItem)) { - const keys = Object.keys(this._children); - if (keys.length === 1) { - return this._children[keys[0]]; + if (this._children.size === 1) { + return this._children.values().next().value; } // if a node had more than one child once, it will never be skipped again - if (keys.length > 1) { + if (this._children.size > 1) { this._showedMoreThanOne = true; } } -- GitLab