Be more defensive around SortedList key

Fixes #3885
Part of microsoft/vscode#151225
This commit is contained in:
Daniel Imms
2022-07-11 05:50:20 -07:00
parent b6885a67e7
commit adcf841a39
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