From 5c8a9084e3e52c528ac14ce5035e4c7d9d060dd1 Mon Sep 17 00:00:00 2001 From: Daniel Imms <2193314+Tyriar@users.noreply.github.com> Date: Sat, 20 Apr 2024 08:41:22 -0700 Subject: [PATCH 01/10] Add mass decoration test button Part of #4911 --- demo/client.ts | 30 +++++++++++++++++++++++++++++- demo/index.html | 1 + 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/demo/client.ts b/demo/client.ts index 7e0830a583..a3e58051c8 100644 --- a/demo/client.ts +++ b/demo/client.ts @@ -44,7 +44,7 @@ if ('WebAssembly' in window) { // Pulling in the module's types relies on the above, it's looks a // little weird here as we're importing "this" module -import { Terminal as TerminalType, ITerminalOptions } from '@xterm/xterm'; +import { Terminal as TerminalType, ITerminalOptions, type IDisposable } from '@xterm/xterm'; export interface IWindowWithTerminal extends Window { term: TerminalType; @@ -255,6 +255,7 @@ if (document.location.pathname === '/test') { document.getElementById('add-grapheme-clusters').addEventListener('click', addGraphemeClusters); document.getElementById('add-decoration').addEventListener('click', addDecoration); document.getElementById('add-overview-ruler').addEventListener('click', addOverviewRuler); + document.getElementById('decoration-stress-test').addEventListener('click', decorationStressTest); document.getElementById('weblinks-test').addEventListener('click', testWeblinks); document.getElementById('bce').addEventListener('click', coloredErase); addVtButtons(); @@ -1170,6 +1171,33 @@ function addOverviewRuler(): void { term.registerDecoration({ marker: term.registerMarker(10), overviewRulerOptions: { color: '#ffffff80', position: 'full' } }); } +let decorationStressTestDecorations: IDisposable[] | undefined; +function decorationStressTest(): void { + if (decorationStressTestDecorations) { + for (const d of decorationStressTestDecorations) { + d.dispose(); + } + decorationStressTestDecorations = undefined; + } else { + const t = term as Terminal; + const buffer = t.buffer.active; + const cursorY = buffer.baseY + buffer.cursorY; + decorationStressTestDecorations = []; + for (const x of [0, 5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60, 65, 70, 75, 80, 85, 90, 95]) { + for (let y = 0; y < t.buffer.active.length; y++) { + const cursorOffsetY = y - cursorY; + decorationStressTestDecorations.push(t.registerDecoration({ + marker: t.registerMarker(cursorOffsetY), + x, + width: 4, + backgroundColor: '#FF0000', + overviewRulerOptions: { color: '#FF0000' } + })); + } + } + } +} + (console as any).image = (source: ImageData | HTMLCanvasElement, scale: number = 1) => { function getBox(width: number, height: number): any { return { diff --git a/demo/index.html b/demo/index.html index caff2ca213..238c988668 100644 --- a/demo/index.html +++ b/demo/index.html @@ -102,6 +102,7 @@

Test

Decorations
+
Weblinks Addon
From dc541d549543f4bff48993074a7222d923d1aa72 Mon Sep 17 00:00:00 2001 From: Daniel Imms <2193314+Tyriar@users.noreply.github.com> Date: Sat, 20 Apr 2024 10:32:30 -0700 Subject: [PATCH 02/10] Optimize SortedList.delete by batching to idle task --- src/common/SortedList.ts | 43 ++++++++++++++++++++++-- src/common/services/DecorationService.ts | 3 +- 2 files changed, 43 insertions(+), 3 deletions(-) diff --git a/src/common/SortedList.ts b/src/common/SortedList.ts index c325009119..0fb71e4eda 100644 --- a/src/common/SortedList.ts +++ b/src/common/SortedList.ts @@ -3,6 +3,8 @@ * @license MIT */ +import { IdleTaskQueue } from 'common/TaskQueue'; + // Work variables to avoid garbage collection. let i = 0; @@ -12,7 +14,10 @@ let i = 0; * includes the by key iterator. */ export class SortedList { - private readonly _array: T[] = []; + private _array: T[] = []; + private readonly _deletedIndices: Set = new Set(); + private readonly _cleanupDeletedTask = new IdleTaskQueue(); + private _isCleaningUp = false; constructor( private readonly _getKey: (value: T) => number @@ -21,9 +26,13 @@ export class SortedList { public clear(): void { this._array.length = 0; + this._deletedIndices.clear(); + this._cleanupDeletedTask.clear(); + this._isCleaningUp = false; } public insert(value: T): void { + this._flushCleanupDeleted(); if (this._array.length === 0) { this._array.push(value); return; @@ -49,14 +58,42 @@ export class SortedList { } do { if (this._array[i] === value) { - this._array.splice(i, 1); + if (this._deletedIndices.size === 0) { + this._cleanupDeletedTask.enqueue(() => this._cleanupDeleted()); + } + this._deletedIndices.add(i); return true; } } while (++i < this._array.length && this._getKey(this._array[i]) === key); return false; } + private _cleanupDeleted(): void { + this._isCleaningUp = true; + const sortedDeletedIndices = Array.from(this._deletedIndices).sort((a, b) => a - b); + let sortedDeletedIndicesIndex = 0; + const newArray = new Array(this._array.length - sortedDeletedIndices.length); + let newArrayIndex = 0; + for (let i = 0; i < this._array.length; i++) { + if (sortedDeletedIndices[sortedDeletedIndicesIndex] === i) { + sortedDeletedIndicesIndex++; + } else { + newArray[newArrayIndex++] = this._array[i]; + } + } + this._array = newArray; + this._deletedIndices.clear(); + this._isCleaningUp = false; + } + + private _flushCleanupDeleted(): void { + if (!this._isCleaningUp) { + this._cleanupDeletedTask.flush(); + } + } + public *getKeyIterator(key: number): IterableIterator { + this._flushCleanupDeleted(); if (this._array.length === 0) { return; } @@ -73,6 +110,7 @@ export class SortedList { } public forEachByKey(key: number, callback: (value: T) => void): void { + this._flushCleanupDeleted(); if (this._array.length === 0) { return; } @@ -89,6 +127,7 @@ export class SortedList { } public values(): IterableIterator { + this._flushCleanupDeleted(); // Duplicate the array to avoid issues when _array changes while iterating return [...this._array].values(); } diff --git a/src/common/services/DecorationService.ts b/src/common/services/DecorationService.ts index da75915276..c9be78af2f 100644 --- a/src/common/services/DecorationService.ts +++ b/src/common/services/DecorationService.ts @@ -45,7 +45,8 @@ export class DecorationService extends Disposable implements IDecorationService const decoration = new Decoration(options); if (decoration) { const markerDispose = decoration.marker.onDispose(() => decoration.dispose()); - decoration.onDispose(() => { + const listener = decoration.onDispose(() => { + listener.dispose(); if (decoration) { if (this._decorations.delete(decoration)) { this._onDecorationRemoved.fire(decoration); From 3af11c2b1f8c79cf61b040231e851f6d523c4e19 Mon Sep 17 00:00:00 2001 From: Daniel Imms <2193314+Tyriar@users.noreply.github.com> Date: Sat, 20 Apr 2024 10:47:40 -0700 Subject: [PATCH 03/10] Optimize SortedList.insert by batching to idle task --- src/common/SortedList.ts | 58 +++++++++++++++++++++++++++++++++------- 1 file changed, 49 insertions(+), 9 deletions(-) diff --git a/src/common/SortedList.ts b/src/common/SortedList.ts index 0fb71e4eda..0aba3668f4 100644 --- a/src/common/SortedList.ts +++ b/src/common/SortedList.ts @@ -15,8 +15,14 @@ let i = 0; */ export class SortedList { private _array: T[] = []; + + private readonly _addedValues: Set = new Set(); + private readonly _cleanupAddedTask = new IdleTaskQueue(); + private _isCleaningUpAdded = false; + private readonly _deletedIndices: Set = new Set(); - private readonly _cleanupDeletedTask = new IdleTaskQueue(); + + private readonly _cleanupTask = new IdleTaskQueue(); private _isCleaningUp = false; constructor( @@ -27,21 +33,52 @@ export class SortedList { public clear(): void { this._array.length = 0; this._deletedIndices.clear(); - this._cleanupDeletedTask.clear(); + this._cleanupTask.clear(); this._isCleaningUp = false; } public insert(value: T): void { this._flushCleanupDeleted(); - if (this._array.length === 0) { - this._array.push(value); - return; + if (this._addedValues.size === 0) { + this._cleanupAddedTask.enqueue(() => this._cleanupAdded()); + } + this._addedValues.add(value); + // if (this._array.length === 0) { + // this._array.push(value); + // return; + // } + // i = this._search(this._getKey(value)); + // this._array.splice(i, 0, value); + } + + private _cleanupAdded(): void { + const sortedAddedValues = Array.from(this._addedValues).sort((a, b) => this._getKey(a) - this._getKey(b)); + let sortedAddedValuesIndex = 0; + let arrayIndex = 0; + + const newArray = new Array(this._array.length + this._addedValues.size); + + for (let newArrayIndex = 0; newArrayIndex < newArray.length; newArrayIndex++) { + if (arrayIndex >= this._array.length || this._getKey(sortedAddedValues[sortedAddedValuesIndex]) === this._getKey(this._array[arrayIndex])) { + newArray[newArrayIndex] = sortedAddedValues[sortedAddedValuesIndex]; + sortedAddedValuesIndex++; + } else { + newArray[newArrayIndex] = this._array[arrayIndex++]; + } + } + + this._array = newArray; + this._addedValues.clear(); + } + + private _flushCleanupAdded(): void { + if (!this._isCleaningUpAdded) { + this._cleanupAddedTask.flush(); } - i = this._search(this._getKey(value)); - this._array.splice(i, 0, value); } public delete(value: T): boolean { + this._flushCleanupAdded(); if (this._array.length === 0) { return false; } @@ -59,7 +96,7 @@ export class SortedList { do { if (this._array[i] === value) { if (this._deletedIndices.size === 0) { - this._cleanupDeletedTask.enqueue(() => this._cleanupDeleted()); + this._cleanupTask.enqueue(() => this._cleanupDeleted()); } this._deletedIndices.add(i); return true; @@ -88,11 +125,12 @@ export class SortedList { private _flushCleanupDeleted(): void { if (!this._isCleaningUp) { - this._cleanupDeletedTask.flush(); + this._cleanupTask.flush(); } } public *getKeyIterator(key: number): IterableIterator { + this._flushCleanupAdded(); this._flushCleanupDeleted(); if (this._array.length === 0) { return; @@ -110,6 +148,7 @@ export class SortedList { } public forEachByKey(key: number, callback: (value: T) => void): void { + this._flushCleanupAdded(); this._flushCleanupDeleted(); if (this._array.length === 0) { return; @@ -127,6 +166,7 @@ export class SortedList { } public values(): IterableIterator { + this._flushCleanupAdded(); this._flushCleanupDeleted(); // Duplicate the array to avoid issues when _array changes while iterating return [...this._array].values(); From 69c4966804d6fc33ebe27bf3f38901a6e5875aff Mon Sep 17 00:00:00 2001 From: Daniel Imms <2193314+Tyriar@users.noreply.github.com> Date: Sat, 20 Apr 2024 10:48:55 -0700 Subject: [PATCH 04/10] Consistent naming --- src/common/SortedList.ts | 63 ++++++++++++++++++---------------------- 1 file changed, 28 insertions(+), 35 deletions(-) diff --git a/src/common/SortedList.ts b/src/common/SortedList.ts index 0aba3668f4..42dc7ef352 100644 --- a/src/common/SortedList.ts +++ b/src/common/SortedList.ts @@ -16,14 +16,13 @@ let i = 0; export class SortedList { private _array: T[] = []; - private readonly _addedValues: Set = new Set(); - private readonly _cleanupAddedTask = new IdleTaskQueue(); - private _isCleaningUpAdded = false; + private readonly _insertedValues: Set = new Set(); + private readonly _flushInsertedTask = new IdleTaskQueue(); + private _isFlushingInserted = false; private readonly _deletedIndices: Set = new Set(); - - private readonly _cleanupTask = new IdleTaskQueue(); - private _isCleaningUp = false; + private readonly _flushDeletedTask = new IdleTaskQueue(); + private _isflushingDeleted = false; constructor( private readonly _getKey: (value: T) => number @@ -33,30 +32,24 @@ export class SortedList { public clear(): void { this._array.length = 0; this._deletedIndices.clear(); - this._cleanupTask.clear(); - this._isCleaningUp = false; + this._flushDeletedTask.clear(); + this._isflushingDeleted = false; } public insert(value: T): void { this._flushCleanupDeleted(); - if (this._addedValues.size === 0) { - this._cleanupAddedTask.enqueue(() => this._cleanupAdded()); - } - this._addedValues.add(value); - // if (this._array.length === 0) { - // this._array.push(value); - // return; - // } - // i = this._search(this._getKey(value)); - // this._array.splice(i, 0, value); + if (this._insertedValues.size === 0) { + this._flushInsertedTask.enqueue(() => this._flushInserted()); + } + this._insertedValues.add(value); } - private _cleanupAdded(): void { - const sortedAddedValues = Array.from(this._addedValues).sort((a, b) => this._getKey(a) - this._getKey(b)); + private _flushInserted(): void { + const sortedAddedValues = Array.from(this._insertedValues).sort((a, b) => this._getKey(a) - this._getKey(b)); let sortedAddedValuesIndex = 0; let arrayIndex = 0; - const newArray = new Array(this._array.length + this._addedValues.size); + const newArray = new Array(this._array.length + this._insertedValues.size); for (let newArrayIndex = 0; newArrayIndex < newArray.length; newArrayIndex++) { if (arrayIndex >= this._array.length || this._getKey(sortedAddedValues[sortedAddedValuesIndex]) === this._getKey(this._array[arrayIndex])) { @@ -68,17 +61,17 @@ export class SortedList { } this._array = newArray; - this._addedValues.clear(); + this._insertedValues.clear(); } - private _flushCleanupAdded(): void { - if (!this._isCleaningUpAdded) { - this._cleanupAddedTask.flush(); + private _flushCleanupInserted(): void { + if (!this._isFlushingInserted) { + this._flushInsertedTask.flush(); } } public delete(value: T): boolean { - this._flushCleanupAdded(); + this._flushCleanupInserted(); if (this._array.length === 0) { return false; } @@ -96,7 +89,7 @@ export class SortedList { do { if (this._array[i] === value) { if (this._deletedIndices.size === 0) { - this._cleanupTask.enqueue(() => this._cleanupDeleted()); + this._flushDeletedTask.enqueue(() => this._flushDeleted()); } this._deletedIndices.add(i); return true; @@ -105,8 +98,8 @@ export class SortedList { return false; } - private _cleanupDeleted(): void { - this._isCleaningUp = true; + private _flushDeleted(): void { + this._isflushingDeleted = true; const sortedDeletedIndices = Array.from(this._deletedIndices).sort((a, b) => a - b); let sortedDeletedIndicesIndex = 0; const newArray = new Array(this._array.length - sortedDeletedIndices.length); @@ -120,17 +113,17 @@ export class SortedList { } this._array = newArray; this._deletedIndices.clear(); - this._isCleaningUp = false; + this._isflushingDeleted = false; } private _flushCleanupDeleted(): void { - if (!this._isCleaningUp) { - this._cleanupTask.flush(); + if (!this._isflushingDeleted) { + this._flushDeletedTask.flush(); } } public *getKeyIterator(key: number): IterableIterator { - this._flushCleanupAdded(); + this._flushCleanupInserted(); this._flushCleanupDeleted(); if (this._array.length === 0) { return; @@ -148,7 +141,7 @@ export class SortedList { } public forEachByKey(key: number, callback: (value: T) => void): void { - this._flushCleanupAdded(); + this._flushCleanupInserted(); this._flushCleanupDeleted(); if (this._array.length === 0) { return; @@ -166,7 +159,7 @@ export class SortedList { } public values(): IterableIterator { - this._flushCleanupAdded(); + this._flushCleanupInserted(); this._flushCleanupDeleted(); // Duplicate the array to avoid issues when _array changes while iterating return [...this._array].values(); From 45fd3c900f2cfe448a129ba5b7525bacb24c9b9f Mon Sep 17 00:00:00 2001 From: Daniel Imms <2193314+Tyriar@users.noreply.github.com> Date: Sat, 20 Apr 2024 10:52:43 -0700 Subject: [PATCH 05/10] Only flush when needed --- src/common/SortedList.ts | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/common/SortedList.ts b/src/common/SortedList.ts index 42dc7ef352..8a2ad9cc12 100644 --- a/src/common/SortedList.ts +++ b/src/common/SortedList.ts @@ -22,7 +22,7 @@ export class SortedList { private readonly _deletedIndices: Set = new Set(); private readonly _flushDeletedTask = new IdleTaskQueue(); - private _isflushingDeleted = false; + private _isFlushingDeleted = false; constructor( private readonly _getKey: (value: T) => number @@ -33,7 +33,7 @@ export class SortedList { this._array.length = 0; this._deletedIndices.clear(); this._flushDeletedTask.clear(); - this._isflushingDeleted = false; + this._isFlushingDeleted = false; } public insert(value: T): void { @@ -65,7 +65,7 @@ export class SortedList { } private _flushCleanupInserted(): void { - if (!this._isFlushingInserted) { + if (!this._isFlushingInserted && this._insertedValues.size > 0) { this._flushInsertedTask.flush(); } } @@ -99,7 +99,7 @@ export class SortedList { } private _flushDeleted(): void { - this._isflushingDeleted = true; + this._isFlushingDeleted = true; const sortedDeletedIndices = Array.from(this._deletedIndices).sort((a, b) => a - b); let sortedDeletedIndicesIndex = 0; const newArray = new Array(this._array.length - sortedDeletedIndices.length); @@ -113,11 +113,11 @@ export class SortedList { } this._array = newArray; this._deletedIndices.clear(); - this._isflushingDeleted = false; + this._isFlushingDeleted = false; } private _flushCleanupDeleted(): void { - if (!this._isflushingDeleted) { + if (!this._isFlushingDeleted && this._deletedIndices.size > 0) { this._flushDeletedTask.flush(); } } From 71dddbc8b93f141413c32c20443639681b5ad914 Mon Sep 17 00:00:00 2001 From: Daniel Imms <2193314+Tyriar@users.noreply.github.com> Date: Sat, 20 Apr 2024 10:57:39 -0700 Subject: [PATCH 06/10] Move from set to array --- src/common/SortedList.ts | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/src/common/SortedList.ts b/src/common/SortedList.ts index 8a2ad9cc12..eb88f36885 100644 --- a/src/common/SortedList.ts +++ b/src/common/SortedList.ts @@ -16,11 +16,11 @@ let i = 0; export class SortedList { private _array: T[] = []; - private readonly _insertedValues: Set = new Set(); + private readonly _insertedValues: T[] = []; private readonly _flushInsertedTask = new IdleTaskQueue(); private _isFlushingInserted = false; - private readonly _deletedIndices: Set = new Set(); + private readonly _deletedIndices: number[] = []; private readonly _flushDeletedTask = new IdleTaskQueue(); private _isFlushingDeleted = false; @@ -31,17 +31,20 @@ export class SortedList { public clear(): void { this._array.length = 0; - this._deletedIndices.clear(); + this._insertedValues.length = 0; + this._flushInsertedTask.clear(); + this._isFlushingInserted = false; + this._deletedIndices.length = 0; this._flushDeletedTask.clear(); this._isFlushingDeleted = false; } public insert(value: T): void { this._flushCleanupDeleted(); - if (this._insertedValues.size === 0) { + if (this._insertedValues.length === 0) { this._flushInsertedTask.enqueue(() => this._flushInserted()); } - this._insertedValues.add(value); + this._insertedValues.push(value); } private _flushInserted(): void { @@ -49,7 +52,7 @@ export class SortedList { let sortedAddedValuesIndex = 0; let arrayIndex = 0; - const newArray = new Array(this._array.length + this._insertedValues.size); + const newArray = new Array(this._array.length + this._insertedValues.length); for (let newArrayIndex = 0; newArrayIndex < newArray.length; newArrayIndex++) { if (arrayIndex >= this._array.length || this._getKey(sortedAddedValues[sortedAddedValuesIndex]) === this._getKey(this._array[arrayIndex])) { @@ -61,11 +64,11 @@ export class SortedList { } this._array = newArray; - this._insertedValues.clear(); + this._insertedValues.length = 0; } private _flushCleanupInserted(): void { - if (!this._isFlushingInserted && this._insertedValues.size > 0) { + if (!this._isFlushingInserted && this._insertedValues.length > 0) { this._flushInsertedTask.flush(); } } @@ -88,10 +91,10 @@ export class SortedList { } do { if (this._array[i] === value) { - if (this._deletedIndices.size === 0) { + if (this._deletedIndices.length === 0) { this._flushDeletedTask.enqueue(() => this._flushDeleted()); } - this._deletedIndices.add(i); + this._deletedIndices.push(i); return true; } } while (++i < this._array.length && this._getKey(this._array[i]) === key); @@ -112,12 +115,12 @@ export class SortedList { } } this._array = newArray; - this._deletedIndices.clear(); + this._deletedIndices.length = 0; this._isFlushingDeleted = false; } private _flushCleanupDeleted(): void { - if (!this._isFlushingDeleted && this._deletedIndices.size > 0) { + if (!this._isFlushingDeleted && this._deletedIndices.length > 0) { this._flushDeletedTask.flush(); } } From ef1152a8fb0c5e7bdf5bda2bb433b7fe148c93b7 Mon Sep 17 00:00:00 2001 From: Daniel Imms <2193314+Tyriar@users.noreply.github.com> Date: Sat, 20 Apr 2024 10:59:17 -0700 Subject: [PATCH 07/10] Doc --- src/common/SortedList.ts | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/common/SortedList.ts b/src/common/SortedList.ts index eb88f36885..67e1047e08 100644 --- a/src/common/SortedList.ts +++ b/src/common/SortedList.ts @@ -9,9 +9,10 @@ import { IdleTaskQueue } from 'common/TaskQueue'; let i = 0; /** - * A generic list that is maintained in sorted order and allows values with duplicate keys. This - * list is based on binary search and as such locating a key will take O(log n) amortized, this - * includes the by key iterator. + * A generic list that is maintained in sorted order and allows values with duplicate keys. Deferred + * batch insertion and deletion is used to significantly reduce the time it takes to insert and + * delete a large amount of items in succession. This list is based on binary search and as such + * locating a key will take O(log n) amortized, this includes the by key iterator. */ export class SortedList { private _array: T[] = []; From 73fe7015b7776b80c78927ae28809a73f5b8ffcc Mon Sep 17 00:00:00 2001 From: Daniel Imms <2193314+Tyriar@users.noreply.github.com> Date: Sat, 20 Apr 2024 11:00:41 -0700 Subject: [PATCH 08/10] Use sort on object --- src/common/SortedList.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/common/SortedList.ts b/src/common/SortedList.ts index 67e1047e08..1fb4f962df 100644 --- a/src/common/SortedList.ts +++ b/src/common/SortedList.ts @@ -49,7 +49,7 @@ export class SortedList { } private _flushInserted(): void { - const sortedAddedValues = Array.from(this._insertedValues).sort((a, b) => this._getKey(a) - this._getKey(b)); + const sortedAddedValues = this._insertedValues.sort((a, b) => this._getKey(a) - this._getKey(b)); let sortedAddedValuesIndex = 0; let arrayIndex = 0; @@ -104,7 +104,7 @@ export class SortedList { private _flushDeleted(): void { this._isFlushingDeleted = true; - const sortedDeletedIndices = Array.from(this._deletedIndices).sort((a, b) => a - b); + const sortedDeletedIndices = this._deletedIndices.sort((a, b) => a - b); let sortedDeletedIndicesIndex = 0; const newArray = new Array(this._array.length - sortedDeletedIndices.length); let newArrayIndex = 0; From a4a7ce843ce1555c9ab6159ddba39100536db222 Mon Sep 17 00:00:00 2001 From: Daniel Imms <2193314+Tyriar@users.noreply.github.com> Date: Sat, 20 Apr 2024 11:08:28 -0700 Subject: [PATCH 09/10] Reduce gc pressure in api verify integers --- src/browser/public/Terminal.ts | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/browser/public/Terminal.ts b/src/browser/public/Terminal.ts index a6349225df..56edbc5078 100644 --- a/src/browser/public/Terminal.ts +++ b/src/browser/public/Terminal.ts @@ -20,6 +20,8 @@ import { IBufferNamespace as IBufferNamespaceApi, IDecoration, IDecorationOption */ const CONSTRUCTOR_ONLY_OPTIONS = ['cols', 'rows']; +let $value = 0; + export class Terminal extends Disposable implements ITerminalApi { private _core: ITerminal; private _addonManager: AddonManager; @@ -249,16 +251,16 @@ export class Terminal extends Disposable implements ITerminalApi { } private _verifyIntegers(...values: number[]): void { - for (const value of values) { - if (value === Infinity || isNaN(value) || value % 1 !== 0) { + for ($value of values) { + if ($value === Infinity || isNaN($value) || $value % 1 !== 0) { throw new Error('This API only accepts integers'); } } } private _verifyPositiveIntegers(...values: number[]): void { - for (const value of values) { - if (value && (value === Infinity || isNaN(value) || value % 1 !== 0 || value < 0)) { + for ($value of values) { + if ($value && ($value === Infinity || isNaN($value) || $value % 1 !== 0 || $value < 0)) { throw new Error('This API only accepts positive integers'); } } From 6b4bf428de661f7269b777de68454dd08175050d Mon Sep 17 00:00:00 2001 From: Daniel Imms <2193314+Tyriar@users.noreply.github.com> Date: Sat, 20 Apr 2024 11:15:14 -0700 Subject: [PATCH 10/10] Fix tests --- src/common/SortedList.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/common/SortedList.ts b/src/common/SortedList.ts index 1fb4f962df..82b6dfa6af 100644 --- a/src/common/SortedList.ts +++ b/src/common/SortedList.ts @@ -56,7 +56,7 @@ export class SortedList { const newArray = new Array(this._array.length + this._insertedValues.length); for (let newArrayIndex = 0; newArrayIndex < newArray.length; newArrayIndex++) { - if (arrayIndex >= this._array.length || this._getKey(sortedAddedValues[sortedAddedValuesIndex]) === this._getKey(this._array[arrayIndex])) { + if (arrayIndex >= this._array.length || this._getKey(sortedAddedValues[sortedAddedValuesIndex]) <= this._getKey(this._array[arrayIndex])) { newArray[newArrayIndex] = sortedAddedValues[sortedAddedValuesIndex]; sortedAddedValuesIndex++; } else {