Skip to content

Commit df82915

Browse files
committed
Remove isDisposed checks in model
1 parent f050eaa commit df82915

11 files changed

Lines changed: 15 additions & 351 deletions

src/vs/editor/common/core/position.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ export class Position implements IEditorPosition {
1212
public column: number;
1313

1414
constructor(lineNumber: number, column: number) {
15-
this.lineNumber = lineNumber;
16-
this.column = column;
15+
this.lineNumber = lineNumber|0;
16+
this.column = column|0;
1717
}
1818

1919
public equals(other:IPosition): boolean {

src/vs/editor/common/editorCommon.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3528,8 +3528,8 @@ export class HorizontalRange {
35283528
public width: number;
35293529

35303530
constructor(left:number, width:number) {
3531-
this.left = left;
3532-
this.width = width;
3531+
this.left = left|0;
3532+
this.width = width|0;
35333533
}
35343534
}
35353535

src/vs/editor/common/model/editableTextModel.ts

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -66,18 +66,10 @@ export class EditableTextModel extends TextModelWithDecorations implements edito
6666
}
6767

6868
public pushStackElement(): void {
69-
if (this._isDisposed) {
70-
throw new Error('EditableTextModel.pushStackElement: Model is disposed');
71-
}
72-
7369
this._commandManager.pushStackElement();
7470
}
7571

7672
public pushEditOperations(beforeCursorState:editorCommon.IEditorSelection[], editOperations:editorCommon.IIdentifiedSingleEditOperation[], cursorStateComputer:editorCommon.ICursorStateComputer): editorCommon.IEditorSelection[] {
77-
if (this._isDisposed) {
78-
throw new Error('EditableTextModel.pushEditOperations: Model is disposed');
79-
}
80-
8173
return this.deferredEmit(() => {
8274
return this._commandManager.pushEditOperation(beforeCursorState, editOperations, cursorStateComputer);
8375
});
@@ -532,10 +524,6 @@ export class EditableTextModel extends TextModelWithDecorations implements edito
532524
}
533525

534526
public undo(): editorCommon.IEditorSelection[] {
535-
if (this._isDisposed) {
536-
throw new Error('EditableTextModel.undo: Model is disposed');
537-
}
538-
539527
return this._withDeferredEvents(() => {
540528
this._isUndoing = true;
541529
let r = this._commandManager.undo();
@@ -552,10 +540,6 @@ export class EditableTextModel extends TextModelWithDecorations implements edito
552540
}
553541

554542
public redo(): editorCommon.IEditorSelection[] {
555-
if (this._isDisposed) {
556-
throw new Error('EditableTextModel.redo: Model is disposed');
557-
}
558-
559543
return this._withDeferredEvents(() => {
560544
this._isRedoing = true;
561545
let r = this._commandManager.redo();
@@ -572,10 +556,6 @@ export class EditableTextModel extends TextModelWithDecorations implements edito
572556
}
573557

574558
public setEditableRange(range:editorCommon.IRange): void {
575-
if (this._isDisposed) {
576-
throw new Error('EditableTextModel.setEditableRange: Model is disposed');
577-
}
578-
579559
this._commandManager.clear();
580560
if (this._hasEditableRange) {
581561
this.removeTrackedRange(this._editableRangeId);
@@ -590,18 +570,10 @@ export class EditableTextModel extends TextModelWithDecorations implements edito
590570
}
591571

592572
public hasEditableRange(): boolean {
593-
if (this._isDisposed) {
594-
throw new Error('EditableTextModel.hasEditableRange: Model is disposed');
595-
}
596-
597573
return this._hasEditableRange;
598574
}
599575

600576
public getEditableRange(): editorCommon.IEditorRange {
601-
if (this._isDisposed) {
602-
throw new Error('EditableTextModel.getEditableRange: Model is disposed');
603-
}
604-
605577
if (this._hasEditableRange) {
606578
return this.getTrackedRange(this._editableRangeId);
607579
} else {

src/vs/editor/common/model/mirrorModel.ts

Lines changed: 0 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,6 @@ export class AbstractMirrorModel extends TextModelWithTokens implements editorCo
3232
}
3333

3434
public getModeId(): string {
35-
if (this._isDisposed) {
36-
throw new Error('AbstractMirrorModel.getModeId: Model is disposed');
37-
}
38-
3935
return this.getMode().getId();
4036
}
4137

@@ -63,10 +59,6 @@ export class AbstractMirrorModel extends TextModelWithTokens implements editorCo
6359
}
6460

6561
public getAssociatedResource(): URI {
66-
if (this._isDisposed) {
67-
throw new Error('AbstractMirrorModel.getAssociatedResource: Model is disposed');
68-
}
69-
7062
return this._associatedResource;
7163
}
7264

@@ -82,10 +74,6 @@ export class AbstractMirrorModel extends TextModelWithTokens implements editorCo
8274
}
8375

8476
public getRangeFromOffsetAndLength(offset:number, length:number):editorCommon.IRange {
85-
if (this._isDisposed) {
86-
throw new Error('AbstractMirrorModel.getRangeFromOffsetAndLength: Model is disposed');
87-
}
88-
8977
var startPosition = this.getPositionFromOffset(offset),
9078
endPosition = this.getPositionFromOffset(offset + length);
9179
return {
@@ -97,10 +85,6 @@ export class AbstractMirrorModel extends TextModelWithTokens implements editorCo
9785
}
9886

9987
public getOffsetAndLengthFromRange(range:editorCommon.IRange):{offset:number; length:number;} {
100-
if (this._isDisposed) {
101-
throw new Error('AbstractMirrorModel.getOffsetAndLengthFromRange: Model is disposed');
102-
}
103-
10488
var startOffset = this.getOffsetFromPosition({ lineNumber: range.startLineNumber, column: range.startColumn }),
10589
endOffset = this.getOffsetFromPosition({ lineNumber: range.endLineNumber, column: range.endColumn });
10690
return {
@@ -110,10 +94,6 @@ export class AbstractMirrorModel extends TextModelWithTokens implements editorCo
11094
}
11195

11296
public getPositionFromOffset(offset:number):editorCommon.IPosition {
113-
if (this._isDisposed) {
114-
throw new Error('AbstractMirrorModel.getPositionFromOffset: Model is disposed');
115-
}
116-
11797
this._ensurePrefixSum();
11898

11999
let r = this._lineStarts.getIndexOf(offset);
@@ -124,28 +104,17 @@ export class AbstractMirrorModel extends TextModelWithTokens implements editorCo
124104
}
125105

126106
public getOffsetFromPosition(position:editorCommon.IPosition): number {
127-
if (this._isDisposed) {
128-
throw new Error('AbstractMirrorModel.getOffsetFromPosition: Model is disposed');
129-
}
130-
131107
return this.getLineStart(position.lineNumber) + position.column - 1 /* column isn't zero-index based */;
132108
}
133109

134110
public getLineStart(lineNumber:number): number {
135-
if (this._isDisposed) {
136-
throw new Error('AbstractMirrorModel.getLineStart: Model is disposed');
137-
}
138-
139111
this._ensurePrefixSum();
140112

141113
var lineIndex = Math.min(lineNumber, this._lines.length) - 1;
142114
return this._lineStarts.getAccumulatedValue(lineIndex - 1);
143115
}
144116

145117
public getAllWordsWithRange(): editorCommon.IRangeWithText[] {
146-
if (this._isDisposed) {
147-
throw new Error('AbstractMirrorModel.getAllWordsWithRange: Model is disposed');
148-
}
149118
if (this._lines.length > 10000) {
150119
// This is a very heavy method, unavailable for very heavy models
151120
return [];
@@ -169,10 +138,6 @@ export class AbstractMirrorModel extends TextModelWithTokens implements editorCo
169138
}
170139

171140
public getAllWords(): string[] {
172-
if (this._isDisposed) {
173-
throw new Error('AbstractMirrorModel.getAllWords: Model is disposed');
174-
}
175-
176141
var result:string[] = [];
177142
this._lines.forEach((line) => {
178143
this.wordenize(line.text).forEach((info) => {
@@ -183,10 +148,6 @@ export class AbstractMirrorModel extends TextModelWithTokens implements editorCo
183148
}
184149

185150
public getAllUniqueWords(skipWordOnce?:string) : string[] {
186-
if (this._isDisposed) {
187-
throw new Error('AbstractMirrorModel.getAllUniqueWords: Model is disposed');
188-
}
189-
190151
var foundSkipWord = false;
191152
var uniqueWords = {};
192153
return this.getAllWords().filter((word) => {
@@ -308,10 +269,6 @@ export class MirrorModel extends AbstractMirrorModel implements editorCommon.IMi
308269
}
309270

310271
public getEmbeddedAtPosition(position:editorCommon.IPosition):editorCommon.IMirrorModel {
311-
if (this._isDisposed) {
312-
throw new Error('MirrorModel.getEmbeddedAtPosition: Model is disposed');
313-
}
314-
315272
var modeAtPosition = this.getModeAtPosition(position.lineNumber, position.column);
316273
if (this._embeddedModels.hasOwnProperty(modeAtPosition.getId())) {
317274
return this._embeddedModels[modeAtPosition.getId()];
@@ -320,10 +277,6 @@ export class MirrorModel extends AbstractMirrorModel implements editorCommon.IMi
320277
}
321278

322279
public getAllEmbedded():editorCommon.IMirrorModel[] {
323-
if (this._isDisposed) {
324-
throw new Error('MirrorModel.getAllEmbedded: Model is disposed');
325-
}
326-
327280
return Object.keys(this._embeddedModels).map((embeddedModeId) => this._embeddedModels[embeddedModeId]);
328281
}
329282

@@ -434,10 +387,6 @@ export class MirrorModel extends AbstractMirrorModel implements editorCommon.IMi
434387
}
435388

436389
public onEvents(events:IMirrorModelEvents) : boolean {
437-
if (this._isDisposed) {
438-
throw new Error('MirrorModel.onEvents: Model is disposed');
439-
}
440-
441390
let changed = false;
442391
for (let i = 0, len = events.contentChanged.length; i < len; i++) {
443392
let contentChangedEvent = events.contentChanged[i];

src/vs/editor/common/model/model.ts

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -95,21 +95,13 @@ export class Model extends EditableTextModel implements IModel {
9595
}
9696

9797
public onBeforeAttached(): void {
98-
if (this._isDisposed) {
99-
throw new Error('Model.onBeforeAttached: Model is disposed');
100-
}
101-
10298
this._attachedEditorCount++;
10399

104100
// Warm up tokens for the editor
105101
this._warmUpTokens();
106102
}
107103

108104
public onBeforeDetached(): void {
109-
if (this._isDisposed) {
110-
throw new Error('Model.onBeforeDetached: Model is disposed');
111-
}
112-
113105
this._attachedEditorCount--;
114106

115107
// Intentional empty (for now)
@@ -120,10 +112,6 @@ export class Model extends EditableTextModel implements IModel {
120112
}
121113

122114
public getAssociatedResource(): URI {
123-
if (this._isDisposed) {
124-
throw new Error('Model.getAssociatedResource: Model is disposed');
125-
}
126-
127115
return this._associatedResource;
128116
}
129117
}

0 commit comments

Comments
 (0)