Skip to content

Commit

Permalink
Bug 1941085 - Add ElementIsLinkedWell checks to DoublyLinkedList. r=p…
Browse files Browse the repository at this point in the history
  • Loading branch information
jensstutte committed Feb 25, 2025
1 parent 3b5e831 commit bc8ea86
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions mfbt/DoublyLinkedList.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
};

/**
Expand Down

0 comments on commit bc8ea86

Please sign in to comment.