Bug 1181444 (part 1) - Remove nsBaseHashtable::EnumerateRead(). r=froydnj.
authorNicholas Nethercote <nnethercote@mozilla.com>
Sun, 22 Nov 2015 14:39:01 -0800
changeset 274549 b181b44bfeeba4e1115d8eedebbfe267226d9b65
parent 274548 58c11f8db0b1e70cdc941c79ddf216e6436a8afe
child 274550 52f9c007281d973138d8b91a1a5fe6a3af717cd0
child 274677 a18630f9ab42ddfde03ba8c7757a42069c48c7ed
push id68625
push usernnethercote@mozilla.com
push dateMon, 30 Nov 2015 05:27:55 +0000
treeherdermozilla-inbound@b181b44bfeeb [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersfroydnj
bugs1181444
milestone45.0a1
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
Bug 1181444 (part 1) - Remove nsBaseHashtable::EnumerateRead(). r=froydnj.
xpcom/glue/nsBaseHashtable.h
xpcom/tests/TestHashtables.cpp
--- a/xpcom/glue/nsBaseHashtable.h
+++ b/xpcom/glue/nsBaseHashtable.h
@@ -2,26 +2,24 @@
 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
 /* 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 nsBaseHashtable_h__
 #define nsBaseHashtable_h__
 
-#include "mozilla/DebugOnly.h"
 #include "mozilla/MemoryReporting.h"
 #include "mozilla/Move.h"
 #include "nsTHashtable.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.
+// These type is returned by |EnumFunction| and controls the behavior of
+// Enumerate(). The PLD/PL_D prefix is because it originated in PLDHashTable,
+// but that class no longer uses it.
 enum PLDHashOperator
 {
   PL_DHASH_NEXT = 0,          // enumerator says continue
   PL_DHASH_REMOVE = 2         // enumerator says remove
 };
 
 template<class KeyClass, class DataType, class UserDataType>
 class nsBaseHashtable; // forward declaration
@@ -155,46 +153,16 @@ public:
    * remove the data for the associated key
    * @param aKey the key to remove from the hashtable
    */
   void Remove(KeyType aKey) { this->RemoveEntry(aKey); }
 
   /**
    * function type provided by the application for enumeration.
    * @param aKey the key being enumerated
-   * @param aData data being enumerated
-   * @param aUserArg passed unchanged from Enumerate
-   * @return @link PLDHashOperator::PL_DHASH_NEXT PL_DHASH_NEXT @endlink
-   */
-  typedef PLDHashOperator (*EnumReadFunction)(KeyType aKey,
-                                              UserDataType aData,
-                                              void* aUserArg);
-
-  /**
-   * enumerate entries in the hashtable, without allowing changes
-   * WARNING: this function is deprecated. Please use Iterator instead.
-   * @param aEnumFunc enumeration callback
-   * @param aUserArg passed unchanged to the EnumReadFunction
-   */
-  uint32_t EnumerateRead(EnumReadFunction aEnumFunc, void* aUserArg) const
-  {
-    uint32_t n = 0;
-    for (auto iter = this->mTable.ConstIter(); !iter.Done(); iter.Next()) {
-      auto entry = static_cast<EntryType*>(iter.Get());
-      mozilla::DebugOnly<PLDHashOperator> op =
-        aEnumFunc(entry->GetKey(), entry->mData, aUserArg);
-      n++;
-      MOZ_ASSERT(!(op & PL_DHASH_REMOVE));
-    }
-    return n;
-  }
-
-  /**
-   * function type provided by the application for enumeration.
-   * @param aKey the key being enumerated
    * @param aData Reference to data being enumerated, may be altered. e.g. for
    *        nsInterfaceHashtable this is an nsCOMPtr reference...
    * @parm aUserArg passed unchanged from Enumerate
    * @return bitflag combination of
    *   @link PLDHashOperator::PL_DHASH_REMOVE @endlink or
    *   @link PLDHashOperator::PL_DHASH_NEXT PL_DHASH_NEXT @endlink
    */
   typedef PLDHashOperator (*EnumFunction)(KeyType aKey,
--- a/xpcom/tests/TestHashtables.cpp
+++ b/xpcom/tests/TestHashtables.cpp
@@ -166,35 +166,22 @@ testTHashtable(nsTHashtable<EntityToUnic
   uint32_t count = nsTIterPrint(hash);
   if (count != numEntries) {
     printf("  Bad count!\n");
     exit (6);
   }
 }
 
 PLDHashOperator
-nsDEnumRead(const uint32_t& aKey, const char* aData, void* userArg) {
-  printf("  enumerated %u = \"%s\"\n", aKey, aData);
-  return PL_DHASH_NEXT;
-}
-
-PLDHashOperator
 nsDEnum(const uint32_t& aKey, const char*& aData, void* userArg) {
   printf("  enumerated %u = \"%s\"\n", aKey, aData);
   return PL_DHASH_NEXT;
 }
 
 PLDHashOperator
-nsCEnumRead(const nsACString& aKey, TestUniChar* aData, void* userArg) {
-  printf("  enumerated \"%s\" = %c\n",
-         PromiseFlatCString(aKey).get(), aData->GetChar());
-  return PL_DHASH_NEXT;
-}
-
-PLDHashOperator
 nsCEnum(const nsACString& aKey, nsAutoPtr<TestUniChar>& aData, void* userArg) {
     printf("  enumerated \"%s\" = %c\n", 
            PromiseFlatCString(aKey).get(), aData->GetChar());
   return PL_DHASH_NEXT;
 }
 
 //
 // all this nsIFoo stuff was copied wholesale from TestCOMPtr.cpp
@@ -335,45 +322,25 @@ CreateIFoo( IFoo** result )
     foop->AddRef();
     *result = foop;
 
     printf("<<CreateIFoo()\n");
     return NS_OK;
   }
 
 PLDHashOperator
-nsIEnumRead(const uint32_t& aKey, IFoo* aFoo, void* userArg) {
-  nsAutoCString str;
-  aFoo->GetString(str);
-
-  printf("  enumerated %u = \"%s\"\n", aKey, str.get());
-  return PL_DHASH_NEXT;
-}
-
-PLDHashOperator
 nsIEnum(const uint32_t& aKey, nsCOMPtr<IFoo>& aData, void* userArg) {
   nsAutoCString str;
   aData->GetString(str);
 
   printf("  enumerated %u = \"%s\"\n", aKey, str.get());
   return PL_DHASH_NEXT;
 }
 
 PLDHashOperator
-nsIEnum2Read(nsISupports* aKey, uint32_t aData, void* userArg) {
-  nsAutoCString str;
-  nsCOMPtr<IFoo> foo = do_QueryInterface(aKey);
-  foo->GetString(str);
-
-
-  printf("  enumerated \"%s\" = %u\n", str.get(), aData);
-  return PL_DHASH_NEXT;
-}
-
-PLDHashOperator
 nsIEnum2(nsISupports* aKey, uint32_t& aData, void* userArg) {
   nsAutoCString str;
   nsCOMPtr<IFoo> foo = do_QueryInterface(aKey);
   foo->GetString(str);
 
   printf("  enumerated \"%s\" = %u\n", str.get(), aData);
   return PL_DHASH_NEXT;
 }
@@ -453,27 +420,31 @@ main(void) {
     printf("Found %s\n", str);
   }
 
   printf("Testing nonexistent entries...");
   if (UniToEntity.Get(99446, &str)) {
     printf("FOUND! BAD!\n");
     exit (13);
   }
-      
+
   printf("not found; good.\n");
-      
+
   printf("Enumerating:\n");
-  
-  count = UniToEntity.EnumerateRead(nsDEnumRead, nullptr);
+
+  count = 0;
+  for (auto iter = UniToEntity.Iter(); !iter.Done(); iter.Next()) {
+    printf("  enumerated %u = \"%s\"\n", iter.Key(), iter.UserData());
+    count++;
+  }
   if (count != ENTITY_COUNT) {
     printf("  Bad count!\n");
     exit (14);
   }
-  
+
   printf("Clearing...");
   UniToEntity.Clear();
   printf("OK\n");
 
   printf("Checking count...");
   count = UniToEntity.Enumerate(nsDEnum, nullptr);
   if (count) {
     printf("  Clear did not remove all entries.\n");
@@ -513,27 +484,32 @@ main(void) {
     printf("Found %c\n", myChar->GetChar());
   }
 
   printf("Testing nonexistent entries...");
   if (EntToUniClass.Get(NS_LITERAL_CSTRING("xxxx"), &myChar)) {
     printf("FOUND! BAD!\n");
     exit (19);
   }
-      
+
   printf("not found; good.\n");
-      
+
   printf("Enumerating:\n");
-  
-  count = EntToUniClass.EnumerateRead(nsCEnumRead, nullptr);
+
+  count = 0;
+  for (auto iter = EntToUniClass.Iter(); !iter.Done(); iter.Next()) {
+    printf("  enumerated \"%s\" = %c\n",
+           PromiseFlatCString(iter.Key()).get(), iter.UserData()->GetChar());
+    count++;
+  }
   if (count != ENTITY_COUNT) {
     printf("  Bad count!\n");
     exit (20);
   }
-  
+
   printf("Clearing...\n");
   EntToUniClass.Clear();
   printf("  Clearing OK\n");
 
   printf("Checking count...");
   count = EntToUniClass.Enumerate(nsCEnum, nullptr);
   if (count) {
     printf("  Clear did not remove all entries.\n");
@@ -566,41 +542,48 @@ main(void) {
     printf("OK...\n");
   }
 
   printf("Testing Get:\n");
   uint32_t myChar2;
 
   for (i = 0; i < ENTITY_COUNT; ++i) {
     printf("  Getting entry %s...", gEntities[i].mStr);
-    
+
     if (!EntToUniClass2.Get(fooArray[i], &myChar2)) {
       printf("FAILED\n");
       exit (24);
     }
 
     printf("Found %c\n", myChar2);
   }
 
   printf("Testing nonexistent entries...");
   if (EntToUniClass2.Get((nsISupports*) 0x55443316, &myChar2)) {
     printf("FOUND! BAD!\n");
     exit (25);
   }
-      
+
   printf("not found; good.\n");
-      
+
   printf("Enumerating:\n");
-  
-  count = EntToUniClass2.EnumerateRead(nsIEnum2Read, nullptr);
+
+  count = 0;
+  for (auto iter = EntToUniClass2.Iter(); !iter.Done(); iter.Next()) {
+    nsAutoCString s;
+    nsCOMPtr<IFoo> foo = do_QueryInterface(iter.Key());
+    foo->GetString(s);
+    printf("  enumerated \"%s\" = %u\n", s.get(), iter.UserData());
+    count++;
+  }
   if (count != ENTITY_COUNT) {
     printf("  Bad count!\n");
     exit (26);
   }
-  
+
   printf("Clearing...\n");
   EntToUniClass2.Clear();
   printf("  Clearing OK\n");
 
   printf("Checking count...");
   count = EntToUniClass2.Enumerate(nsIEnum2, nullptr);
   if (count) {
     printf("  Clear did not remove all entries.\n");
@@ -628,17 +611,17 @@ main(void) {
     UniToEntClass2.Put(gEntities[i].mUnicode, foo);
     printf("OK...\n");
   }
 
   printf("Testing Get:\n");
 
   for (i = 0; i < ENTITY_COUNT; ++i) {
     printf("  Getting entry %s...", gEntities[i].mStr);
-    
+
     nsCOMPtr<IFoo> myEnt;
     if (!UniToEntClass2.Get(gEntities[i].mUnicode, getter_AddRefs(myEnt))) {
       printf("FAILED\n");
       exit (30);
     }
 
     nsAutoCString myEntStr;
     myEnt->GetString(myEntStr);
@@ -646,27 +629,33 @@ main(void) {
   }
 
   printf("Testing nonexistent entries...");
   nsCOMPtr<IFoo> myEnt;
   if (UniToEntClass2.Get(9462, getter_AddRefs(myEnt))) {
     printf("FOUND! BAD!\n");
     exit (31);
   }
-      
+
   printf("not found; good.\n");
-      
+
   printf("Enumerating:\n");
-  
-  count = UniToEntClass2.EnumerateRead(nsIEnumRead, nullptr);
+
+  count = 0;
+  for (auto iter = UniToEntClass2.Iter(); !iter.Done(); iter.Next()) {
+    nsAutoCString s;
+    iter.UserData()->GetString(s);
+    printf("  enumerated %u = \"%s\"\n", iter.Key(), s.get());
+    count++;
+  }
   if (count != ENTITY_COUNT) {
     printf("  Bad count!\n");
     exit (32);
   }
-  
+
   printf("Clearing...\n");
   UniToEntClass2.Clear();
   printf("  Clearing OK\n");
 
   printf("Checking count...");
   count = UniToEntClass2.Enumerate(nsIEnum, nullptr);
   if (count) {
     printf("  Clear did not remove all entries.\n");