Backout 04a196339ca4 (bug 1181443, part 3) so that bug 1182961's patches can be backed out.
authorNicholas Nethercote <nnethercote@mozilla.com>
Thu, 06 Aug 2015 16:28:13 -0700
changeset 288370 11f2aec8187f0463c3f89f5e28698a90d1618acd
parent 288369 6d3e153efe5bff3b3cc4f3690924491aec6856b2
child 288371 d7734e7adeb21c316cae38b88b83c411488e0563
push id5067
push userraliiev@mozilla.com
push dateMon, 21 Sep 2015 14:04:52 +0000
treeherdermozilla-beta@14221ffe5b2f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
bugs1181443, 1182961
milestone42.0a1
backs out04a196339ca46b8e87544fdff12f9f855b27c803
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Backout 04a196339ca4 (bug 1181443, part 3) so that bug 1182961's patches can be backed out.
xpcom/glue/nsBaseHashtable.h
xpcom/glue/nsTHashtable.h
--- a/xpcom/glue/nsBaseHashtable.h
+++ b/xpcom/glue/nsBaseHashtable.h
@@ -8,27 +8,16 @@
 #define nsBaseHashtable_h__
 
 #include "mozilla/MemoryReporting.h"
 #include "mozilla/Move.h"
 #include "nsTHashtable.h"
 #include "prlock.h"
 #include "nsDebug.h"
 
-// These are the codes returned by |EnumReadFunction| and |EnumFunction|, which
-// control the behavior of EnumerateRead() and Enumerate(). The PLD/PL_D prefix
-// is because they originated in PLDHashTable, but that class no longer uses
-// them.
-enum PLDHashOperator
-{
-  PL_DHASH_NEXT = 0,          // enumerator says continue
-  PL_DHASH_STOP = 1,          // enumerator says stop
-  PL_DHASH_REMOVE = 2         // enumerator says remove
-};
-
 template<class KeyClass, class DataType, class UserDataType>
 class nsBaseHashtable; // forward declaration
 
 /**
  * the private nsTHashtable::EntryType class used by nsBaseHashtable
  * @see nsTHashtable for the specification of this class
  * @see nsBaseHashtable for template parameters
  */
--- a/xpcom/glue/nsTHashtable.h
+++ b/xpcom/glue/nsTHashtable.h
@@ -67,16 +67,26 @@
  *   }</pre>
  *
  * @see nsInterfaceHashtable
  * @see nsDataHashtable
  * @see nsClassHashtable
  * @author "Benjamin Smedberg <bsmedberg@covad.net>"
  */
 
+// These are the codes returned by |Enumerator| functions, which control
+// EnumerateEntry()'s behavior. The PLD/PL_D prefix is because they originated
+// in PLDHashTable, but that class no longer uses them.
+enum PLDHashOperator
+{
+  PL_DHASH_NEXT = 0,          // enumerator says continue
+  PL_DHASH_STOP = 1,          // enumerator says stop
+  PL_DHASH_REMOVE = 2         // enumerator says remove
+};
+
 template<class EntryType>
 class MOZ_NEEDS_NO_VTABLE_TYPE nsTHashtable
 {
   typedef mozilla::fallible_t fallible_t;
 
 public:
   // Separate constructors instead of default aInitLength parameter since
   // otherwise the default no-arg constructor isn't found.
@@ -174,16 +184,56 @@ public:
    * @param aEntry   the entry-pointer to remove (obtained from GetEntry or
    *                 the enumerator
    */
   void RawRemoveEntry(EntryType* aEntry)
   {
     PL_DHashTableRawRemove(&mTable, aEntry);
   }
 
+  /**
+   * client must provide an <code>Enumerator</code> function for
+   *   EnumerateEntries
+   * @param     aEntry the entry being enumerated
+   * @param     userArg passed unchanged from <code>EnumerateEntries</code>
+   * @return    combination of flags
+   *            @link PLDHashOperator::PL_DHASH_NEXT PL_DHASH_NEXT @endlink ,
+   *            @link PLDHashOperator::PL_DHASH_STOP PL_DHASH_STOP @endlink ,
+   *            @link PLDHashOperator::PL_DHASH_REMOVE PL_DHASH_REMOVE @endlink
+   */
+  typedef PLDHashOperator (*Enumerator)(EntryType* aEntry, void* userArg);
+
+  /**
+   * Enumerate all the entries of the function. If any entries are removed via
+   * a PL_DHASH_REMOVE return value from |aEnumFunc|, the table may be shrunk
+   * at the end. Use RawRemoveEntry() instead if you wish to remove an entry
+   * without possibly shrinking the table.
+   * WARNING: this function is deprecated. Please use Iterator instead.
+   * @param     enumFunc the <code>Enumerator</code> function to call
+   * @param     userArg a pointer to pass to the
+   *            <code>Enumerator</code> function
+   * @return    the number of entries actually enumerated
+   */
+  uint32_t EnumerateEntries(Enumerator aEnumFunc, void* aUserArg)
+  {
+    uint32_t n = 0;
+    for (auto iter = mTable.Iter(); !iter.Done(); iter.Next()) {
+      auto entry = static_cast<EntryType*>(iter.Get());
+      PLDHashOperator op = aEnumFunc(entry, aUserArg);
+      n++;
+      if (op & PL_DHASH_REMOVE) {
+        iter.Remove();
+      }
+      if (op & PL_DHASH_STOP) {
+        break;
+      }
+    }
+    return n;
+  }
+
   // This is an iterator that also allows entry removal. Example usage:
   //
   //   for (auto iter = table.Iter(); !iter.Done(); iter.Next()) {
   //     Entry* entry = iter.Get();
   //     // ... do stuff with |entry| ...
   //     // ... possibly call iter.Remove() once ...
   //   }
   //