Bug 1478879 - Remove Range/Enum use in DMD. r=mccr8 draft
authorNicholas Nethercote <nnethercote@mozilla.com>
Fri, 27 Jul 2018 12:21:01 +1000
changeset 825236 5f0e9368f4535c32725f539cb56fbf051142aac9
parent 825230 ff6d4414438f09f699d52e1758b76fb5c0d24fa6
child 825237 d8603c4c578f1074ca8fc5fde1d629a499ebf97f
push id118039
push usernnethercote@mozilla.com
push dateWed, 01 Aug 2018 03:07:33 +0000
reviewersmccr8
bugs1478879
milestone63.0a1
Bug 1478879 - Remove Range/Enum use in DMD. r=mccr8 MozReview-Commit-ID: 8XWhe34jRSz
memory/replace/dmd/DMD.cpp
--- a/memory/replace/dmd/DMD.cpp
+++ b/memory/replace/dmd/DMD.cpp
@@ -602,18 +602,18 @@ public:
     return newString;
   }
 
   size_t
   SizeOfExcludingThis(mozilla::MallocSizeOf aMallocSizeOf) const
   {
     size_t n = 0;
     n += mSet.sizeOfExcludingThis(aMallocSizeOf);
-    for (auto r = mSet.all(); !r.empty(); r.popFront()) {
-      n += aMallocSizeOf(r.front());
+    for (auto iter = mSet.iter(); !iter.done(); iter.next()) {
+      n += aMallocSizeOf(iter.get());
     }
     return n;
   }
 
 private:
   struct StringHasher
   {
       typedef const char* Lookup;
@@ -1129,41 +1129,41 @@ static void
 GatherUsedStackTraces(StackTraceSet& aStackTraces)
 {
   MOZ_ASSERT(gStateLock->IsLocked());
   MOZ_ASSERT(Thread::Fetch()->InterceptsAreBlocked());
 
   aStackTraces.finish();
   MOZ_ALWAYS_TRUE(aStackTraces.init(512));
 
-  for (auto r = gLiveBlockTable->all(); !r.empty(); r.popFront()) {
-    r.front().AddStackTracesToTable(aStackTraces);
+  for (auto iter = gLiveBlockTable->iter(); !iter.done(); iter.next()) {
+    iter.get().AddStackTracesToTable(aStackTraces);
   }
 
-  for (auto r = gDeadBlockTable->all(); !r.empty(); r.popFront()) {
-    r.front().key().AddStackTracesToTable(aStackTraces);
+  for (auto iter = gDeadBlockTable->iter(); !iter.done(); iter.next()) {
+    iter.get().key().AddStackTracesToTable(aStackTraces);
   }
 }
 
 // Delete stack traces that we aren't using, and compact our hashtable.
 static void
 GCStackTraces()
 {
   MOZ_ASSERT(gStateLock->IsLocked());
   MOZ_ASSERT(Thread::Fetch()->InterceptsAreBlocked());
 
   StackTraceSet usedStackTraces;
   GatherUsedStackTraces(usedStackTraces);
 
-  // Delete all unused stack traces from gStackTraceTable.  The Enum destructor
-  // will automatically rehash and compact the table.
-  for (StackTraceTable::Enum e(*gStackTraceTable); !e.empty(); e.popFront()) {
-    StackTrace* const& st = e.front();
+  // Delete all unused stack traces from gStackTraceTable.  The ModIterator
+  // destructor will automatically rehash and compact the table.
+  for (auto iter = gStackTraceTable->modIter(); !iter.done(); iter.next()) {
+    StackTrace* const& st = iter.get();
     if (!usedStackTraces.has(st)) {
-      e.removeFront();
+      iter.remove();
       InfallibleAllocPolicy::delete_(st);
     }
   }
 
   // Schedule a GC when we have twice as many stack traces as we had right after
   // this GC finished.
   gGCStackTraceTableWhenSizeExceeds = 2 * gStackTraceTable->count();
 }
@@ -1656,18 +1656,18 @@ SizeOfInternal(Sizes* aSizes)
   MOZ_ASSERT(gStateLock->IsLocked());
   MOZ_ASSERT(Thread::Fetch()->InterceptsAreBlocked());
 
   aSizes->Clear();
 
   StackTraceSet usedStackTraces;
   GatherUsedStackTraces(usedStackTraces);
 
-  for (auto r = gStackTraceTable->all(); !r.empty(); r.popFront()) {
-    StackTrace* const& st = r.front();
+  for (auto iter = gStackTraceTable->iter(); !iter.done(); iter.next()) {
+    StackTrace* const& st = iter.get();
 
     if (usedStackTraces.has(st)) {
       aSizes->mStackTracesUsed += MallocSizeOf(st);
     } else {
       aSizes->mStackTracesUnused += MallocSizeOf(st);
     }
   }
 
@@ -1696,18 +1696,18 @@ DMDFuncs::ClearReports()
     return;
   }
 
   AutoLockState lock;
 
   // Unreport all blocks that were marked reported by a memory reporter.  This
   // excludes those that were reported on allocation, because they need to keep
   // their reported marking.
-  for (auto r = gLiveBlockTable->all(); !r.empty(); r.popFront()) {
-    r.front().UnreportIfNotReportedOnAlloc();
+  for (auto iter = gLiveBlockTable->iter(); !iter.done(); iter.next()) {
+    iter.get().UnreportIfNotReportedOnAlloc();
   }
 }
 
 class ToIdStringConverter final
 {
 public:
   ToIdStringConverter()
     : mNextId(0)
@@ -1905,51 +1905,51 @@ AnalyzeImpl(UniquePtr<JSONWriteFunc> aWr
       };
 
       // Live blocks.
       if (!gOptions->IsScanMode()) {
         // At this point we typically have many LiveBlocks that differ only in
         // their address. Aggregate them to reduce the size of the output file.
         AggregatedLiveBlockTable agg;
         MOZ_ALWAYS_TRUE(agg.init(8192));
-        for (auto r = gLiveBlockTable->all(); !r.empty(); r.popFront()) {
-          const LiveBlock& b = r.front();
+        for (auto iter = gLiveBlockTable->iter(); !iter.done(); iter.next()) {
+          const LiveBlock& b = iter.get();
           b.AddStackTracesToTable(usedStackTraces);
 
           if (AggregatedLiveBlockTable::AddPtr p = agg.lookupForAdd(&b)) {
             p->value() += 1;
           } else {
             MOZ_ALWAYS_TRUE(agg.add(p, &b, 1));
           }
         }
 
         // Now iterate over the aggregated table.
-        for (auto r = agg.all(); !r.empty(); r.popFront()) {
-          const LiveBlock& b = *r.front().key();
-          size_t num = r.front().value();
+        for (auto iter = agg.iter(); !iter.done(); iter.next()) {
+          const LiveBlock& b = *iter.get().key();
+          size_t num = iter.get().value();
           writeLiveBlock(b, num);
         }
 
       } else {
         // In scan mode we cannot aggregate because we print each live block's
         // address and contents.
-        for (auto r = gLiveBlockTable->all(); !r.empty(); r.popFront()) {
-          const LiveBlock& b = r.front();
+        for (auto iter = gLiveBlockTable->iter(); !iter.done(); iter.next()) {
+          const LiveBlock& b = iter.get();
           b.AddStackTracesToTable(usedStackTraces);
 
           writeLiveBlock(b, 1);
         }
       }
 
       // Dead blocks.
-      for (auto r = gDeadBlockTable->all(); !r.empty(); r.popFront()) {
-        const DeadBlock& b = r.front().key();
+      for (auto iter = gDeadBlockTable->iter(); !iter.done(); iter.next()) {
+        const DeadBlock& b = iter.get().key();
         b.AddStackTracesToTable(usedStackTraces);
 
-        size_t num = r.front().value();
+        size_t num = iter.get().value();
         MOZ_ASSERT(num > 0);
 
         writer.StartObjectElement(writer.SingleLineStyle);
         {
           writer.IntProperty("req", b.ReqSize());
           if (b.SlopSize() > 0) {
             writer.IntProperty("slop", b.SlopSize());
           }
@@ -1965,18 +1965,18 @@ AnalyzeImpl(UniquePtr<JSONWriteFunc> aWr
       }
     }
     writer.EndArray();
 
     StatusMsg("  Constructing the stack trace table...\n");
 
     writer.StartObjectProperty("traceTable");
     {
-      for (auto r = usedStackTraces.all(); !r.empty(); r.popFront()) {
-        const StackTrace* const st = r.front();
+      for (auto iter = usedStackTraces.iter(); !iter.done(); iter.next()) {
+        const StackTrace* const st = iter.get();
         writer.StartArrayProperty(isc.ToIdString(st), writer.SingleLineStyle);
         {
           for (uint32_t i = 0; i < st->Length(); i++) {
             const void* pc = st->Pc(i);
             writer.StringElement(isc.ToIdString(pc));
             MOZ_ALWAYS_TRUE(usedPcs.put(pc));
           }
         }
@@ -1987,18 +1987,18 @@ AnalyzeImpl(UniquePtr<JSONWriteFunc> aWr
 
     StatusMsg("  Constructing the stack frame table...\n");
 
     writer.StartObjectProperty("frameTable");
     {
       static const size_t locBufLen = 1024;
       char locBuf[locBufLen];
 
-      for (PointerSet::Enum e(usedPcs); !e.empty(); e.popFront()) {
-        const void* const pc = e.front();
+      for (auto iter = usedPcs.iter(); !iter.done(); iter.next()) {
+        const void* const pc = iter.get();
 
         // Use 0 for the frame number. See the JSON format description comment
         // in DMD.h to understand why.
         locService->GetLocation(0, pc, locBuf, locBufLen);
         writer.StringProperty(isc.ToIdString(pc), locBuf);
       }
     }
     writer.EndObject();