Bug 1941085 - Add ElementIsLinkedWell checks to DoublyLinkedList. r=pbone

Differential Revision: https://phabricator.services.mozilla.com/D237063
This commit is contained in:
Jens Stutte
2025-02-25 21:41:57 +00:00
parent a82d2bb804
commit 0abef7030b

View File

@@ -368,6 +368,38 @@ class DoublyLinkedList final {
}
return !ElementNotInList(aElm);
}
/**
* Returns whether an element is linked correctly to its predecessor and/or
* successor, if any. Used for internal sanity checks.
*/
bool ElementIsLinkedWell(T* aElm) {
MOZ_ASSERT(aElm);
if (!ElementProbablyInList(aElm)) {
return false;
}
T* next = ElementAccess::Get(aElm).mNext;
if (next) {
if (ElementAccess::Get(next).mPrev != aElm) {
return false;
}
} else {
if (aElm != mTail) {
return false;
}
}
T* prev = ElementAccess::Get(aElm).mPrev;
if (prev) {
if (ElementAccess::Get(prev).mNext != aElm) {
return false;
}
} else {
if (aElm != mHead) {
return false;
}
}
return true;
}
};
/**