Bug 1473771 - Part 1: Make LinkedList<T>::sizeOfExcludingThis work when element type inherits from multiple LinkedListElement<T>s. r=Waldo draft
authorCameron McCormack <cam@mcc.id.au>
Fri, 06 Jul 2018 10:10:09 +1000
changeset 815242 26129bbc410747c87df132c5c84ebb2a41eb9457
parent 815241 00ecbfd93e13e6cc8c2cf44e2ccf6a630ae526df
child 815243 cb919d0e6b762fc6e80ffab915135550d61c4d5d
push id115472
push userbmo:cam@mcc.id.au
push dateFri, 06 Jul 2018 23:29:01 +0000
reviewersWaldo
bugs1473771
milestone63.0a1
Bug 1473771 - Part 1: Make LinkedList<T>::sizeOfExcludingThis work when element type inherits from multiple LinkedListElement<T>s. r=Waldo MozReview-Commit-ID: KtqGkRKs68f
mfbt/LinkedList.h
--- a/mfbt/LinkedList.h
+++ b/mfbt/LinkedList.h
@@ -553,18 +553,20 @@ public:
    * Measures the memory consumption of the list excluding |this|.  Note that
    * it only measures the list elements themselves.  If the list elements
    * contain pointers to other memory blocks, those blocks must be measured
    * separately during a subsequent iteration over the list.
    */
   size_t sizeOfExcludingThis(MallocSizeOf aMallocSizeOf) const
   {
     size_t n = 0;
-    for (ConstRawType t = getFirst(); t; t = t->getNext()) {
+    ConstRawType t = getFirst();
+    while (t) {
       n += aMallocSizeOf(t);
+      t = static_cast<const LinkedListElement<T>*>(t)->getNext();
     }
     return n;
   }
 
   /*
    * Like sizeOfExcludingThis(), but measures |this| as well.
    */
   size_t sizeOfIncludingThis(MallocSizeOf aMallocSizeOf) const