Skip to content

Commit fe4d68e

Browse files
committed
debug:simplify KeyValueOutputElement, do not cache
1 parent 6881a5b commit fe4d68e

1 file changed

Lines changed: 17 additions & 32 deletions

File tree

src/vs/workbench/parts/debug/common/debugModel.ts

Lines changed: 17 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ export class ValueOutputElement extends OutputElement {
4343
public value: string,
4444
public severity: severity,
4545
public category?: string,
46-
public counter: number = 1
46+
public counter = 1
4747
) {
4848
super();
4949
}
@@ -53,49 +53,34 @@ export class KeyValueOutputElement extends OutputElement {
5353

5454
private static MAX_CHILDREN = 1000; // upper bound of children per value
5555

56-
private children: debug.ITreeElement[];
57-
private _valueName: string;
58-
5956
constructor(public key: string, public valueObj: any, public annotation?: string) {
6057
super();
61-
62-
this._valueName = null;
6358
}
6459

6560
public get value(): string {
66-
if (this._valueName === null) {
67-
if (this.valueObj === null) {
68-
this._valueName = 'null';
69-
} else if (Array.isArray(this.valueObj)) {
70-
this._valueName = `Array[${this.valueObj.length}]`;
71-
} else if (isObject(this.valueObj)) {
72-
this._valueName = 'Object';
73-
} else if (isString(this.valueObj)) {
74-
this._valueName = `"${massageValue(this.valueObj)}"`;
75-
} else {
76-
this._valueName = String(this.valueObj);
77-
}
78-
79-
if (!this._valueName) {
80-
this._valueName = '';
81-
}
61+
if (this.valueObj === null) {
62+
return 'null';
63+
} else if (Array.isArray(this.valueObj)) {
64+
return `Array[${this.valueObj.length}]`;
65+
} else if (isObject(this.valueObj)) {
66+
return 'Object';
67+
} else if (isString(this.valueObj)) {
68+
return `"${massageValue(this.valueObj)}"`;
8269
}
8370

84-
return this._valueName;
71+
return String(this.valueObj) || '';
8572
}
8673

8774
public getChildren(): debug.ITreeElement[] {
88-
if (!this.children) {
89-
if (Array.isArray(this.valueObj)) {
90-
this.children = (<any[]>this.valueObj).slice(0, KeyValueOutputElement.MAX_CHILDREN).map((v, index) => new KeyValueOutputElement(String(index), v, null));
91-
} else if (isObject(this.valueObj)) {
92-
this.children = Object.getOwnPropertyNames(this.valueObj).slice(0, KeyValueOutputElement.MAX_CHILDREN).map(key => new KeyValueOutputElement(key, this.valueObj[key], null));
93-
} else {
94-
this.children = [];
95-
}
75+
if (Array.isArray(this.valueObj)) {
76+
return (<any[]>this.valueObj).slice(0, KeyValueOutputElement.MAX_CHILDREN)
77+
.map((v, index) => new KeyValueOutputElement(String(index), v));
78+
} else if (isObject(this.valueObj)) {
79+
return Object.getOwnPropertyNames(this.valueObj).slice(0, KeyValueOutputElement.MAX_CHILDREN)
80+
.map(key => new KeyValueOutputElement(key, this.valueObj[key]));
9681
}
9782

98-
return this.children;
83+
return [];
9984
}
10085
}
10186

0 commit comments

Comments
 (0)