Bug 718297 - Add EnumerateAll to nsPropertyTable, r=jst
authorOlli Pettay <Olli.Pettay@helsinki.fi>
Sun, 15 Jan 2012 21:02:06 +0200
changeset 84543 047c8ba7d2e405845a1e7940b23c6a9e6407a395
parent 84542 823072af2430cf86939ff891f8bfb11243be7415
child 84555 a895ecb782e1da97478a33d06e78b012cc9b87b2
child 84575 4facc14043a68c8eb5a041fb69e0f9774a2d0faf
push id21855
push useropettay@mozilla.com
push dateSun, 15 Jan 2012 19:22:11 +0000
treeherdermozilla-central@047c8ba7d2e4 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjst
bugs718297
milestone12.0a1
first release with
nightly linux32
047c8ba7d2e4 / 12.0a1 / 20120116031100 / files
nightly linux64
047c8ba7d2e4 / 12.0a1 / 20120116031100 / files
nightly mac
047c8ba7d2e4 / 12.0a1 / 20120116031100 / files
nightly win32
047c8ba7d2e4 / 12.0a1 / 20120116031100 / files
nightly win64
047c8ba7d2e4 / 12.0a1 / 20120116031100 / files
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
releases
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 718297 - Add EnumerateAll to nsPropertyTable, r=jst
content/base/src/nsPropertyTable.cpp
content/base/src/nsPropertyTable.h
--- a/content/base/src/nsPropertyTable.cpp
+++ b/content/base/src/nsPropertyTable.cpp
@@ -156,16 +156,43 @@ nsPropertyTable::Enumerate(nsPropertyOwn
       (PL_DHashTableOperate(&prop->mObjectValueMap, aObject, PL_DHASH_LOOKUP));
     if (PL_DHASH_ENTRY_IS_BUSY(entry)) {
       aCallback(const_cast<void*>(aObject.get()), prop->mName, entry->value,
                  aData);
     }
   }
 }
 
+struct PropertyEnumeratorData
+{
+  nsIAtom* mName;
+  NSPropertyFunc mCallBack;
+  void* mData;
+};
+
+static PLDHashOperator
+PropertyEnumerator(PLDHashTable* aTable, PLDHashEntryHdr* aHdr,
+                   PRUint32 aNumber, void* aArg)
+{
+  PropertyListMapEntry* entry = static_cast<PropertyListMapEntry*>(aHdr);
+  PropertyEnumeratorData* data = static_cast<PropertyEnumeratorData*>(aArg);
+  data->mCallBack(const_cast<void*>(entry->key), data->mName, entry->value,
+                  data->mData);
+  return PL_DHASH_NEXT;
+}
+
+void
+nsPropertyTable::EnumerateAll(NSPropertyFunc aCallBack, void* aData)
+{
+  for (PropertyList* prop = mPropertyList; prop; prop = prop->mNext) {
+    PropertyEnumeratorData data = { prop->mName, aCallBack, aData };
+    PL_DHashTableEnumerate(&prop->mObjectValueMap, PropertyEnumerator, &data);
+  }
+}
+
 void*
 nsPropertyTable::GetPropertyInternal(nsPropertyOwner aObject,
                                      nsIAtom    *aPropertyName,
                                      bool        aRemove,
                                      nsresult   *aResult)
 {
   NS_PRECONDITION(aPropertyName && aObject, "unexpected null param");
   nsresult rv = NS_PROPTABLE_PROP_NOT_THERE;
--- a/content/base/src/nsPropertyTable.h
+++ b/content/base/src/nsPropertyTable.h
@@ -177,16 +177,23 @@ class nsPropertyTable
    * Enumerate the properties for object |aObject|.
    * For every property |aCallback| will be called with as arguments |aObject|,
    * the property name, the property value and |aData|.
    */
   NS_HIDDEN_(void) Enumerate(nsPropertyOwner aObject,
                              NSPropertyFunc aCallback, void *aData);
 
   /**
+   * Enumerate all the properties.
+   * For every property |aCallback| will be called with arguments the owner,
+   * the property name, the property value and |aData|.
+   */
+  NS_HIDDEN_(void) EnumerateAll(NSPropertyFunc aCallback, void *aData);
+
+  /**
    * Deletes all of the properties for all objects in the property
    * table, calling the destructor function for each property.
    */
   NS_HIDDEN_(void) DeleteAllProperties();
 
   nsPropertyTable() : mPropertyList(nsnull) {}  
   ~nsPropertyTable() {
     DeleteAllProperties();