Correctly adjust the backward reference of the next entry when deleting an entry.

This commit is contained in:
kpreisser 2019-01-05 11:45:46 +01:00
parent c4960d3c11
commit 9140cbc29e

View file

@ -223,22 +223,25 @@ namespace ts {
const entry = this.data[key];
delete this.data[key];
// Adjust the linked list references.
const previousElement = entry.previousEntry!;
previousElement.nextEntry = entry.nextEntry;
// Adjust the linked list references of the neighbor entries.
const previousEntry = entry.previousEntry!;
previousEntry.nextEntry = entry.nextEntry;
if (entry.nextEntry) {
entry.nextEntry.previousEntry = previousEntry;
}
// When the deleted entry was the last one, we need to
// adust the endElement reference.
if (this.linkedListEnd === entry) {
this.linkedListEnd = previousEntry;
}
// Adjust the forward reference of the deleted element
// in case an iterator still references it.
entry.previousEntry = undefined;
entry.nextEntry = previousElement;
entry.nextEntry = previousEntry;
entry.skipNext = true;
// When the deleted entry was the last one, we need to
// adust the endElement reference
if (this.linkedListEnd === entry) {
this.linkedListEnd = previousElement;
}
return true;
}
return false;