Bug 1186780: Replace EnumerateRead with new iterators in cycle collection code. r=mccr8
authorKyle Huey <khuey@kylehuey.com>
Sun, 26 Jul 2015 19:29:52 -0700
changeset 273865 d0edab7173aed5c59581a4b90c2cd71dc3417255
parent 273864 c0d0135b9860a3183e0e5f505578a070991bae63
child 273866 8b610e92304910c3bae49fca224817c5723e2afa
push id5067
push userraliiev@mozilla.com
push dateMon, 21 Sep 2015 14:04:52 +0000
treeherdermozilla-esr52@14221ffe5b2f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmccr8
bugs1186780
milestone42.0a1
Bug 1186780: Replace EnumerateRead with new iterators in cycle collection code. r=mccr8
dom/events/DataContainerEvent.cpp
dom/events/DataContainerEvent.h
dom/xbl/nsXBLDocumentInfo.cpp
xpcom/glue/nsBaseHashtable.h
xpcom/glue/nsInterfaceHashtable.h
xpcom/glue/nsRefPtrHashtable.h
--- a/dom/events/DataContainerEvent.cpp
+++ b/dom/events/DataContainerEvent.cpp
@@ -23,21 +23,21 @@ DataContainerEvent::DataContainerEvent(E
       doc->WarnOnceAbout(nsIDocument::eDataContainerEvent);
     }
   }
 }
 
 NS_IMPL_CYCLE_COLLECTION_CLASS(DataContainerEvent)
 
 NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN_INHERITED(DataContainerEvent, Event)
-  tmp->mData.Clear();
+  NS_IMPL_CYCLE_COLLECTION_UNLINK(mData)
 NS_IMPL_CYCLE_COLLECTION_UNLINK_END
 
 NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INHERITED(DataContainerEvent, Event)
-  tmp->mData.EnumerateRead(TraverseEntry, &cb);
+  NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mData)
 NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
 
 NS_IMPL_ADDREF_INHERITED(DataContainerEvent, Event)
 NS_IMPL_RELEASE_INHERITED(DataContainerEvent, Event)
 
 NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION_INHERITED(DataContainerEvent)
   NS_INTERFACE_MAP_ENTRY(nsIDOMDataContainerEvent)
 NS_INTERFACE_MAP_END_INHERITING(Event)
@@ -76,28 +76,16 @@ DataContainerEvent::SetData(JSContext* a
     nsContentUtils::XPConnect()->JSToVariant(aCx, aVal, getter_AddRefs(val));
   if (NS_FAILED(rv)) {
     aRv = rv;
     return;
   }
   aRv = SetData(aKey, val);
 }
 
-PLDHashOperator
-DataContainerEvent::TraverseEntry(const nsAString& aKey,
-                                  nsIVariant* aDataItem,
-                                  void* aUserArg)
-{
-  nsCycleCollectionTraversalCallback *cb =
-    static_cast<nsCycleCollectionTraversalCallback*>(aUserArg);
-  cb->NoteXPCOMChild(aDataItem);
-
-  return PL_DHASH_NEXT;
-}
-
 } // namespace dom
 } // namespace mozilla
 
 using namespace mozilla;
 using namespace mozilla::dom;
 
 nsresult
 NS_NewDOMDataContainerEvent(nsIDOMEvent** aInstancePtrResult,
--- a/dom/events/DataContainerEvent.h
+++ b/dom/events/DataContainerEvent.h
@@ -46,18 +46,15 @@ public:
 
   void SetData(JSContext* aCx, const nsAString& aKey,
                JS::Handle<JS::Value> aVal, ErrorResult& aRv);
 
 protected:
   ~DataContainerEvent() {}
 
 private:
-  static PLDHashOperator
-    TraverseEntry(const nsAString& aKey, nsIVariant* aDataItem, void* aUserArg);
-
   nsInterfaceHashtable<nsStringHashKey, nsIVariant> mData;
 };
 
 } // namespace dom
 } // namespace mozilla
 
 #endif // mozilla_dom_DataContainerEvent_h_
--- a/dom/xbl/nsXBLDocumentInfo.cpp
+++ b/dom/xbl/nsXBLDocumentInfo.cpp
@@ -34,71 +34,48 @@
 
 using namespace mozilla;
 using namespace mozilla::scache;
 using namespace mozilla::dom;
 
 static const char kXBLCachePrefix[] = "xblcache";
 
 /* Implementation file */
-
-static PLDHashOperator
-TraverseProtos(const nsACString &aKey, nsXBLPrototypeBinding *aProto, void* aClosure)
-{
-  nsCycleCollectionTraversalCallback *cb =
-    static_cast<nsCycleCollectionTraversalCallback*>(aClosure);
-  aProto->Traverse(*cb);
-  return PL_DHASH_NEXT;
-}
-
-static PLDHashOperator
-UnlinkProto(const nsACString &aKey, nsXBLPrototypeBinding *aProto, void* aClosure)
-{
-  aProto->Unlink();
-  return PL_DHASH_NEXT;
-}
-
-struct ProtoTracer
-{
-  const TraceCallbacks &mCallbacks;
-  void *mClosure;
-};
-
-static PLDHashOperator
-TraceProtos(const nsACString &aKey, nsXBLPrototypeBinding *aProto, void* aClosure)
-{
-  ProtoTracer* closure = static_cast<ProtoTracer*>(aClosure);
-  aProto->Trace(closure->mCallbacks, closure->mClosure);
-  return PL_DHASH_NEXT;
-}
-
 NS_IMPL_CYCLE_COLLECTION_CLASS(nsXBLDocumentInfo)
 
 NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(nsXBLDocumentInfo)
   if (tmp->mBindingTable) {
-    tmp->mBindingTable->EnumerateRead(UnlinkProto, nullptr);
+    for (auto iter = tmp->mBindingTable->ConstIter();
+         !iter.Done(); iter.Next()) {
+      iter.UserData()->Unlink();
+    }
   }
   NS_IMPL_CYCLE_COLLECTION_UNLINK(mDocument)
 NS_IMPL_CYCLE_COLLECTION_UNLINK_END
 NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(nsXBLDocumentInfo)
   if (tmp->mDocument &&
       nsCCUncollectableMarker::InGeneration(cb, tmp->mDocument->GetMarkedCCGeneration())) {
     NS_IMPL_CYCLE_COLLECTION_TRAVERSE_SCRIPT_OBJECTS
     return NS_SUCCESS_INTERRUPTED_TRAVERSE;
   }
   NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mDocument)
   if (tmp->mBindingTable) {
-    tmp->mBindingTable->EnumerateRead(TraverseProtos, &cb);
+    for (auto iter = tmp->mBindingTable->ConstIter();
+         !iter.Done(); iter.Next()) {
+      iter.UserData()->Traverse(cb);
+    }
   }
   NS_IMPL_CYCLE_COLLECTION_TRAVERSE_SCRIPT_OBJECTS
 NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
 NS_IMPL_CYCLE_COLLECTION_TRACE_BEGIN(nsXBLDocumentInfo)
   if (tmp->mBindingTable) {
-    ProtoTracer closure = { aCallbacks, aClosure };
-    tmp->mBindingTable->EnumerateRead(TraceProtos, &closure);
+    for (auto iter = tmp->mBindingTable->ConstIter();
+         !iter.Done(); iter.Next()) {
+      iter.UserData()->Trace(aCallbacks, aClosure);
+    }
   }
 NS_IMPL_CYCLE_COLLECTION_TRACE_END
 
 static void
 UnmarkXBLJSObject(JS::GCCellPtr aPtr, const char* aName, void* aClosure)
 {
   JS::ExposeObjectToActiveJS(aPtr.toObject());
 }
--- a/xpcom/glue/nsBaseHashtable.h
+++ b/xpcom/glue/nsBaseHashtable.h
@@ -338,51 +338,16 @@ protected:
     void* userArg;
   };
 
   static size_t s_SizeOfStub(PLDHashEntryHdr* aEntry,
                              mozilla::MallocSizeOf aMallocSizeOf,
                              void* aArg);
 };
 
-class nsCycleCollectionTraversalCallback;
-
-struct MOZ_STACK_CLASS nsBaseHashtableCCTraversalData
-{
-  nsBaseHashtableCCTraversalData(nsCycleCollectionTraversalCallback& aCallback,
-                                 const char* aName,
-                                 uint32_t aFlags)
-    : mCallback(aCallback)
-    , mName(aName)
-    , mFlags(aFlags)
-  {
-  }
-
-  nsCycleCollectionTraversalCallback& mCallback;
-  const char* mName;
-  uint32_t mFlags;
-
-};
-
-template<typename K, typename T>
-PLDHashOperator
-ImplCycleCollectionTraverse_EnumFunc(K aKey,
-                                     T aData,
-                                     void* aUserData)
-{
-  nsBaseHashtableCCTraversalData* userData =
-    static_cast<nsBaseHashtableCCTraversalData*>(aUserData);
-
-  CycleCollectionNoteChild(userData->mCallback,
-                           aData,
-                           userData->mName,
-                           userData->mFlags);
-  return PL_DHASH_NEXT;
-}
-
 //
 // nsBaseHashtableET definitions
 //
 
 template<class KeyClass, class DataType>
 nsBaseHashtableET<KeyClass, DataType>::nsBaseHashtableET(KeyTypePointer aKey)
   : KeyClass(aKey)
   , mData()
--- a/xpcom/glue/nsInterfaceHashtable.h
+++ b/xpcom/glue/nsInterfaceHashtable.h
@@ -64,20 +64,19 @@ ImplCycleCollectionUnlink(nsInterfaceHas
 
 template<typename K, typename T>
 inline void
 ImplCycleCollectionTraverse(nsCycleCollectionTraversalCallback& aCallback,
                             const nsInterfaceHashtable<K, T>& aField,
                             const char* aName,
                             uint32_t aFlags = 0)
 {
-  nsBaseHashtableCCTraversalData userData(aCallback, aName, aFlags);
-
-  aField.EnumerateRead(ImplCycleCollectionTraverse_EnumFunc<typename K::KeyType, T*>,
-                       &userData);
+  for (auto iter = aField.ConstIter(); !iter.Done(); iter.Next()) {
+    CycleCollectionNoteChild(aCallback, iter.UserData(), aName, aFlags);
+  }
 }
 
 //
 // nsInterfaceHashtable definitions
 //
 
 template<class KeyClass, class Interface>
 bool
--- a/xpcom/glue/nsRefPtrHashtable.h
+++ b/xpcom/glue/nsRefPtrHashtable.h
@@ -79,20 +79,19 @@ ImplCycleCollectionUnlink(nsRefPtrHashta
 
 template<typename K, typename T>
 inline void
 ImplCycleCollectionTraverse(nsCycleCollectionTraversalCallback& aCallback,
                             nsRefPtrHashtable<K, T>& aField,
                             const char* aName,
                             uint32_t aFlags = 0)
 {
-  nsBaseHashtableCCTraversalData userData(aCallback, aName, aFlags);
-
-  aField.EnumerateRead(ImplCycleCollectionTraverse_EnumFunc<typename K::KeyType, T*>,
-                       &userData);
+  for (auto iter = aField.ConstIter(); !iter.Done(); iter.Next()) {
+    CycleCollectionNoteChild(aCallback, iter.UserData(), aName, aFlags);
+  }
 }
 
 //
 // nsRefPtrHashtable definitions
 //
 
 template<class KeyClass, class RefPtr>
 bool