From 1bef172fe153bc0aba442ee3b3422d706e78b7ec Mon Sep 17 00:00:00 2001 From: Alex Dima Date: Tue, 4 Sep 2018 12:06:47 +0200 Subject: [PATCH] Avoid no-op calls to the renderer --- src/vs/workbench/api/node/extHostTextEditor.ts | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/vs/workbench/api/node/extHostTextEditor.ts b/src/vs/workbench/api/node/extHostTextEditor.ts index eb8afcf4c06..5be78409cb1 100644 --- a/src/vs/workbench/api/node/extHostTextEditor.ts +++ b/src/vs/workbench/api/node/extHostTextEditor.ts @@ -322,6 +322,7 @@ export class ExtHostTextEditor implements vscode.TextEditor { private _visibleRanges: Range[]; private _viewColumn: vscode.ViewColumn; private _disposed: boolean = false; + private _hasDecorationsForKey: { [key: string]: boolean; }; get id(): string { return this._id; } @@ -337,6 +338,7 @@ export class ExtHostTextEditor implements vscode.TextEditor { this._options = new ExtHostTextEditorOptions(this._proxy, this._id, options); this._visibleRanges = visibleRanges; this._viewColumn = viewColumn; + this._hasDecorationsForKey = Object.create(null); } dispose() { @@ -436,6 +438,16 @@ export class ExtHostTextEditor implements vscode.TextEditor { } setDecorations(decorationType: vscode.TextEditorDecorationType, ranges: Range[] | vscode.DecorationOptions[]): void { + const willBeEmpty = (ranges.length === 0); + if (willBeEmpty && !this._hasDecorationsForKey[decorationType.key]) { + // avoid no-op call to the renderer + return; + } + if (willBeEmpty) { + delete this._hasDecorationsForKey[decorationType.key]; + } else { + this._hasDecorationsForKey[decorationType.key] = true; + } this._runOnProxy( () => { if (TypeConverters.isDecorationOptionsArr(ranges)) {