提交 f62a5db2 编写于 作者: I isidor

debug: do not cache children for expressions (tree does that automatically)

上级 43f86ea3
......@@ -106,59 +106,50 @@ export abstract class ExpressionContainer implements debug.IExpressionContainer
private static BASE_CHUNK_SIZE = 100;
public valueChanged: boolean;
private children: TPromise<debug.IExpression[]>;
private _value: string;
constructor(
public stackFrame: debug.IStackFrame,
public reference: number,
private id: string,
private cacheChildren: boolean,
public namedVariables: number,
public indexedVariables: number,
private startOfVariables = 0
) {
// noop
}
) { }
public getChildren(): TPromise<debug.IExpression[]> {
if (!this.cacheChildren || !this.children) {
// only variables with reference > 0 have children.
if (this.reference <= 0) {
this.children = TPromise.as([]);
} else {
if (!this.getChildrenInChunks) {
return this.fetchVariables(undefined, undefined, undefined);
// only variables with reference > 0 have children.
if (this.reference <= 0) {
return TPromise.as([]);
}
if (!this.getChildrenInChunks) {
return this.fetchVariables(undefined, undefined, undefined);
}
// Check if object has named variables, fetch them independent from indexed variables #9670
return (!!this.namedVariables ? this.fetchVariables(undefined, undefined, 'named') : TPromise.as([])).then(childrenArray => {
// Use a dynamic chunk size based on the number of elements #9774
let chunkSize = ExpressionContainer.BASE_CHUNK_SIZE;
while (this.indexedVariables > chunkSize * ExpressionContainer.BASE_CHUNK_SIZE) {
chunkSize *= ExpressionContainer.BASE_CHUNK_SIZE;
}
if (this.indexedVariables > chunkSize) {
// There are a lot of children, create fake intermediate values that represent chunks #9537
const numberOfChunks = Math.ceil(this.indexedVariables / chunkSize);
for (let i = 0; i < numberOfChunks; i++) {
const start = this.startOfVariables + i * chunkSize;
const count = Math.min(chunkSize, this.indexedVariables - i * chunkSize);
childrenArray.push(new Variable(this.stackFrame, this, this.reference, `[${start}..${start + count - 1}]`, '', '', null, count, null, true, start));
}
// Check if object has named variables, fetch them independent from indexed variables #9670
this.children = (!!this.namedVariables ? this.fetchVariables(undefined, undefined, 'named')
: TPromise.as([])).then(childrenArray => {
// Use a dynamic chunk size based on the number of elements #9774
let chunkSize = ExpressionContainer.BASE_CHUNK_SIZE;
while (this.indexedVariables > chunkSize * ExpressionContainer.BASE_CHUNK_SIZE) {
chunkSize *= ExpressionContainer.BASE_CHUNK_SIZE;
}
if (this.indexedVariables > chunkSize) {
// There are a lot of children, create fake intermediate values that represent chunks #9537
const numberOfChunks = Math.ceil(this.indexedVariables / chunkSize);
for (let i = 0; i < numberOfChunks; i++) {
const start = this.startOfVariables + i * chunkSize;
const count = Math.min(chunkSize, this.indexedVariables - i * chunkSize);
childrenArray.push(new Variable(this.stackFrame, this, this.reference, `[${start}..${start + count - 1}]`, '', '', null, count, null, true, start));
}
return childrenArray;
}
return this.fetchVariables(this.startOfVariables, this.indexedVariables, 'indexed')
.then(variables => childrenArray.concat(variables));
});
return childrenArray;
}
}
return this.children;
return this.fetchVariables(this.startOfVariables, this.indexedVariables, 'indexed')
.then(variables => childrenArray.concat(variables));
});
}
public getId(): string {
......@@ -205,8 +196,8 @@ export class Expression extends ExpressionContainer implements debug.IExpression
public available: boolean;
public type: string;
constructor(public name: string, cacheChildren: boolean, id = generateUuid()) {
super(null, 0, id, cacheChildren, 0, 0);
constructor(public name: string, id = generateUuid()) {
super(null, 0, id, 0, 0);
this.available = false;
// name is not set if the expression is just being added
// in that case do not set default value to prevent flashing #14499
......@@ -269,7 +260,7 @@ export class Variable extends ExpressionContainer implements debug.IExpression {
public available = true,
startOfVariables = 0
) {
super(stackFrame, reference, `variable:${parent.getId()}:${name}:${reference}`, true, namedVariables, indexedVariables, startOfVariables);
super(stackFrame, reference, `variable:${parent.getId()}:${name}:${reference}`, namedVariables, indexedVariables, startOfVariables);
this.value = massageValue(value);
}
......@@ -331,7 +322,7 @@ export class Scope extends ExpressionContainer implements debug.IScope {
namedVariables: number,
indexedVariables: number
) {
super(stackFrame, reference, `scope:${stackFrame.getId()}:${name}:${reference}`, true, namedVariables, indexedVariables);
super(stackFrame, reference, `scope:${stackFrame.getId()}:${name}:${reference}`, namedVariables, indexedVariables);
}
}
......@@ -821,7 +812,7 @@ export class Model implements debug.IModel {
}
public addReplExpression(process: debug.IProcess, stackFrame: debug.IStackFrame, name: string): TPromise<void> {
const expression = new Expression(name, true);
const expression = new Expression(name);
this.addReplElements([expression]);
return expression.evaluate(process, stackFrame, 'repl')
.then(() => this._onDidChangeREPLElements.fire());
......@@ -896,7 +887,7 @@ export class Model implements debug.IModel {
}
public addWatchExpression(process: debug.IProcess, stackFrame: debug.IStackFrame, name: string): TPromise<void> {
const we = new Expression(name, false);
const we = new Expression(name);
this.watchExpressions.push(we);
if (!name) {
this._onDidChangeWatchExpressions.fire(we);
......
......@@ -160,7 +160,7 @@ export class DebugHoverWidget implements editorbrowser.IContentWidget {
const matchingExpression = lineContent.substring(expressionRange.startColumn - 1, expressionRange.endColumn);
let promise: TPromise<debug.IExpression>;
if (process.session.configuration.capabilities.supportsEvaluateForHovers) {
const result = new Expression(matchingExpression, true);
const result = new Expression(matchingExpression);
promise = result.evaluate(process, focusedStackFrame, 'hover').then(() => result);
} else {
promise = this.findExpressionInStackFrame(matchingExpression.split('.').map(word => word.trim()).filter(word => !!word));
......
......@@ -402,7 +402,7 @@ export class DebugService implements debug.IDebugService {
let result: Expression[];
try {
result = JSON.parse(this.storageService.get(DEBUG_WATCH_EXPRESSIONS_KEY, StorageScope.WORKSPACE, '[]')).map((watchStoredData: { name: string, id: string }) => {
return new Expression(watchStoredData.name, false, watchStoredData.id);
return new Expression(watchStoredData.name, watchStoredData.id);
});
} catch (e) { }
......
......@@ -34,7 +34,7 @@ suite('Debug - View Model', () => {
test('selected expression', () => {
assert.equal(model.getSelectedExpression(), null);
const expression = new Expression('my expression', false);
const expression = new Expression('my expression');
model.setSelectedExpression(expression);
assert.equal(model.getSelectedExpression(), expression);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册