Skip to content

Commit

Permalink
make model-add-case fast, #35996
Browse files Browse the repository at this point in the history
  • Loading branch information
jrieken authored and egamma committed Oct 31, 2017
1 parent acf5422 commit eddc1aa
Showing 1 changed file with 31 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,10 @@ import { ITelemetryService } from 'vs/platform/telemetry/common/telemetry';
namespace mapset {

export function newSet<E>(from: Set<E>): Set<E> {
let ret = new Set<E>();
from.forEach(ret.add, ret);
return ret;
return new (<any>Set)(from);
// let ret = new Set<E>();
// from.forEach(ret.add, ret);
// return ret;
}

export function setValues<T>(set: Set<T>): T[] {
Expand Down Expand Up @@ -166,7 +167,7 @@ class MainThreadDocumentAndEditorStateComputer {
@ICodeEditorService private _codeEditorService: ICodeEditorService,
@IWorkbenchEditorService private _workbenchEditorService: IWorkbenchEditorService
) {
this._modelService.onModelAdded(this._updateState, this, this._toDispose);
this._modelService.onModelAdded(this._updateStateOnModelAdd, this, this._toDispose);
this._modelService.onModelRemoved(this._updateState, this, this._toDispose);

this._codeEditorService.onCodeEditorAdd(this._onDidAddEditor, this, this._toDispose);
Expand Down Expand Up @@ -196,6 +197,32 @@ class MainThreadDocumentAndEditorStateComputer {
}
}

private _updateStateOnModelAdd(model: IModel): void {
if (model.isTooLargeForHavingARichMode()) {
// ignore
return;
}

if (!this._currentState) {
// too early
this._updateState();
return;
}

// small (fast) delta
this._currentState = new DocumentAndEditorState(
this._currentState.documents.add(model),
this._currentState.editors,
this._currentState.activeEditor
);

this._onDidChangeState(new DocumentAndEditorStateDelta(
[], [model],
[], [],
this._currentState.activeEditor, this._currentState.activeEditor
));
}

private _updateState(): void {

// models: ignore too large models
Expand Down

0 comments on commit eddc1aa

Please sign in to comment.