Bug 989320 - Add cycle collection support for MFBT EnumeratedArray - r=mccr8
authorBenoit Jacob <bjacob@mozilla.com>
Fri, 25 Apr 2014 22:34:03 -0400
changeset 180716 5560662e5eff6751e52f7ef34e804712c918236a
parent 180715 3fbf849caa998a92455583c57d2cce3b6705519b
child 180717 1defae2eeae9be7434de2e3624af5d2a688e6366
push id272
push userpvanderbeken@mozilla.com
push dateMon, 05 May 2014 16:31:18 +0000
reviewersmccr8
bugs989320
milestone31.0a1
Bug 989320 - Add cycle collection support for MFBT EnumeratedArray - r=mccr8
xpcom/glue/EnumeratedArrayCycleCollection.h
xpcom/glue/moz.build
new file mode 100644
--- /dev/null
+++ b/xpcom/glue/EnumeratedArrayCycleCollection.h
@@ -0,0 +1,43 @@
+/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* vim:set ts=2 sw=2 sts=2 et cindent: */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+#ifndef EnumeratedArrayCycleCollection_h_
+#define EnumeratedArrayCycleCollection_h_
+
+#include "mozilla/EnumeratedArray.h"
+#include "nsCycleCollectionTraversalCallback.h"
+
+template <typename IndexType,
+          MOZ_TEMPLATE_ENUM_CLASS_ENUM_TYPE(IndexType) SizeAsEnumValue,
+          typename ValueType>
+inline void
+ImplCycleCollectionUnlink(mozilla::EnumeratedArray<IndexType,
+                                                   SizeAsEnumValue,
+                                                   ValueType>& aField)
+{
+  for (size_t i = 0; i < size_t(SizeAsEnumValue); i++) {
+    aField[IndexType(i)] = nullptr;
+  }
+}
+
+template <typename IndexType,
+          MOZ_TEMPLATE_ENUM_CLASS_ENUM_TYPE(IndexType) SizeAsEnumValue,
+          typename ValueType>
+inline void
+ImplCycleCollectionTraverse(nsCycleCollectionTraversalCallback& aCallback,
+                            mozilla::EnumeratedArray<IndexType,
+                                                     SizeAsEnumValue,
+                                                     ValueType>& aField,
+                            const char* aName,
+                            uint32_t aFlags = 0)
+{
+  aFlags |= CycleCollectionEdgeNameArrayFlag;
+  for (size_t i = 0; i < size_t(SizeAsEnumValue); ++i) {
+    ImplCycleCollectionTraverse(aCallback, aField[IndexType(i)], aName, aFlags);
+  }
+}
+
+#endif // EnumeratedArrayCycleCollection_h_
--- a/xpcom/glue/moz.build
+++ b/xpcom/glue/moz.build
@@ -64,16 +64,17 @@ EXPORTS += [
 ]
 
 EXPORTS.mozilla += [
     'AppData.h',
     'AutoRestore.h',
     'BlockingResourceBase.h',
     'CondVar.h',
     'DeadlockDetector.h',
+    'EnumeratedArrayCycleCollection.h',
     'FileUtils.h',
     'GenericFactory.h',
     'HoldDropJSObjects.h',
     'IntentionalCrash.h',
     'Monitor.h',
     'Mutex.h',
     'Observer.h',
     'ReentrantMonitor.h',