Bug 1182408 - Part 3: Use nsTHashTable::Iterator in mozPersonalDictionary. r=ehsan
authorBirunthan Mohanathas <birunthan@mohanathas.com>
Tue, 14 Jul 2015 10:53:23 -0700
changeset 253097 5ebdd39f878955a2a8de6b9c4acf2bebeb233663
parent 253096 2c709a5c7aff60fdfd39dede4bbcbf14df9d2495
child 253098 31e0ecbf97812fb9f9b5a16dab9680c45809cb0c
push id29061
push userryanvm@gmail.com
push dateThu, 16 Jul 2015 18:53:45 +0000
treeherdermozilla-central@a0f4a688433d [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersehsan
bugs1182408
milestone42.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 1182408 - Part 3: Use nsTHashTable::Iterator in mozPersonalDictionary. r=ehsan
extensions/spellcheck/src/mozPersonalDictionary.cpp
--- a/extensions/spellcheck/src/mozPersonalDictionary.cpp
+++ b/extensions/spellcheck/src/mozPersonalDictionary.cpp
@@ -237,26 +237,16 @@ void mozPersonalDictionary::SyncLoadInte
         if( (NS_OK != convStream->Read(&c, 1, &nRead)) || (nRead != 1)) done = true;
       }
       mDictionaryTable.PutEntry(word.get());
     }
   } while(!done);
   mDirty = false;
 }
 
-// A little helper function to add the key to the list.
-// This is not threadsafe, and only safe if the consumer does not 
-// modify the list.
-static PLDHashOperator
-AddHostToStringArray(nsUnicharPtrHashKey *aEntry, void *aArg)
-{
-  static_cast<nsTArray<nsString>*>(aArg)->AppendElement(nsDependentString(aEntry->GetKey()));
-  return PL_DHASH_NEXT;
-}
-
 /* void Save (); */
 NS_IMETHODIMP mozPersonalDictionary::Save()
 {
   nsCOMPtr<nsIFile> theFile;
   nsresult res;
 
   WaitForLoad();
   if(!mDirty) return NS_OK;
@@ -272,17 +262,19 @@ NS_IMETHODIMP mozPersonalDictionary::Sav
   NS_NewSafeLocalFileOutputStream(getter_AddRefs(outStream), theFile, PR_CREATE_FILE | PR_WRONLY | PR_TRUNCATE ,0664);
 
   // get a buffered output stream 4096 bytes big, to optimize writes
   nsCOMPtr<nsIOutputStream> bufferedOutputStream;
   res = NS_NewBufferedOutputStream(getter_AddRefs(bufferedOutputStream), outStream, 4096);
   if (NS_FAILED(res)) return res;
 
   nsTArray<nsString> array(mDictionaryTable.Count());
-  mDictionaryTable.EnumerateEntries(AddHostToStringArray, &array);
+  for (auto iter = mDictionaryTable.Iter(); !iter.Done(); iter.Next()) {
+    array.AppendElement(nsDependentString(iter.Get()->GetKey()));
+  }
 
   uint32_t bytesWritten;
   nsAutoCString utf8Key;
   for (uint32_t i = 0; i < array.Length(); ++i ) {
     CopyUTF16toUTF8(array[i], utf8Key);
 
     bufferedOutputStream->Write(utf8Key.get(), utf8Key.Length(), &bytesWritten);
     bufferedOutputStream->Write("\n", 1, &bytesWritten);
@@ -302,20 +294,19 @@ NS_IMETHODIMP mozPersonalDictionary::Sav
 NS_IMETHODIMP mozPersonalDictionary::GetWordList(nsIStringEnumerator **aWords)
 {
   NS_ENSURE_ARG_POINTER(aWords);
   *aWords = nullptr;
 
   WaitForLoad();
 
   nsTArray<nsString> *array = new nsTArray<nsString>(mDictionaryTable.Count());
-  if (!array)
-    return NS_ERROR_OUT_OF_MEMORY;
-
-  mDictionaryTable.EnumerateEntries(AddHostToStringArray, array);
+  for (auto iter = mDictionaryTable.Iter(); !iter.Done(); iter.Next()) {
+    array->AppendElement(nsDependentString(iter.Get()->GetKey()));
+  }
 
   array->Sort();
 
   return NS_NewAdoptingStringEnumerator(aWords, array);
 }
 
 /* boolean Check (in wstring word, in wstring language); */
 NS_IMETHODIMP mozPersonalDictionary::Check(const char16_t *aWord, const char16_t *aLanguage, bool *aResult)