Merge pull request #3901 from Tyriar/3885_2

Be more defensive around SortedList key
This commit is contained in:
Daniel Imms
2022-07-11 11:35:18 -07:00
committed by GitHub
2 changed files with 7 additions and 7 deletions
+6 -2
View File
@@ -34,6 +34,9 @@ export class SortedList<T> {
return false;
}
const key = this._getKey(value);
if (key === undefined) {
return false;
}
let i = this._search(key, 0, this._array.length - 1);
if (i === -1) {
return false;
@@ -75,10 +78,11 @@ export class SortedList<T> {
return min;
}
let mid = Math.floor((min + max) / 2);
if (this._getKey(this._array[mid]) > key) {
const midKey = this._getKey(this._array[mid]);
if (midKey > key) {
return this._search(key, min, mid - 1);
}
if (this._getKey(this._array[mid]) < key) {
if (midKey < key) {
return this._search(key, mid + 1, max);
}
// Value found! Since keys can be duplicates, move the result index back to the lowest index
+1 -5
View File
@@ -19,7 +19,7 @@ export class DecorationService extends Disposable implements IDecorationService
* while marker line values do change, they should all change by the same amount so this should
* never become out of order.
*/
private readonly _decorations: SortedList<IInternalDecoration> = new SortedList(e => e.marker.line);
private readonly _decorations: SortedList<IInternalDecoration> = new SortedList(e => e?.marker.line);
private _onDecorationRegistered = this.register(new EventEmitter<IInternalDecoration>());
public get onDecorationRegistered(): IEvent<IInternalDecoration> { return this._onDecorationRegistered.event; }
@@ -28,10 +28,6 @@ export class DecorationService extends Disposable implements IDecorationService
public get decorations(): IterableIterator<IInternalDecoration> { return this._decorations.values(); }
constructor() {
super();
}
public registerDecoration(options: IDecorationOptions): IDecoration | undefined {
if (options.marker.isDisposed) {
return undefined;