Commit 0954ebd2 authored by Simon Giesecke's avatar Simon Giesecke
Browse files

Bug 708901 - Migrate to nsTHashSet in extensions/spellcheck. r=masayuki

parent bf3ef3a7
Loading
Loading
Loading
Loading
+9 −20
Original line number Diff line number Diff line
@@ -301,7 +301,7 @@ void mozPersonalDictionary::SyncLoadInternal() {
        if ((NS_OK != convStream->Read(&c, 1, &nRead)) || (nRead != 1))
          done = true;
      }
      mDictionaryTable.PutEntry(word);
      mDictionaryTable.Insert(word);
    }
  } while (!done);
}
@@ -348,15 +348,8 @@ NS_IMETHODIMP mozPersonalDictionary::Save() {
    return res;
  }

  nsTArray<nsString> array;
  nsString* elems = array.AppendElements(mDictionaryTable.Count());
  for (auto iter = mDictionaryTable.Iter(); !iter.Done(); iter.Next()) {
    elems->Assign(iter.Get()->GetKey());
    elems++;
  }

  nsCOMPtr<nsIRunnable> runnable =
      new mozPersonalDictionarySave(this, theFile, std::move(array));
  nsCOMPtr<nsIRunnable> runnable = new mozPersonalDictionarySave(
      this, theFile, mozilla::ToTArray<nsTArray<nsString>>(mDictionaryTable));
  res = target->Dispatch(runnable, NS_DISPATCH_NORMAL);
  if (NS_WARN_IF(NS_FAILED(res))) {
    return res;
@@ -370,12 +363,8 @@ NS_IMETHODIMP mozPersonalDictionary::GetWordList(nsIStringEnumerator** aWords) {

  WaitForLoad();

  nsTArray<nsString>* array = new nsTArray<nsString>();
  nsString* elems = array->AppendElements(mDictionaryTable.Count());
  for (auto iter = mDictionaryTable.Iter(); !iter.Done(); iter.Next()) {
    elems->Assign(iter.Get()->GetKey());
    elems++;
  }
  nsTArray<nsString>* array = new nsTArray<nsString>(
      mozilla::ToTArray<nsTArray<nsString>>(mDictionaryTable));

  array->Sort();

@@ -388,7 +377,7 @@ mozPersonalDictionary::Check(const nsAString& aWord, bool* aResult) {

  WaitForLoad();

  *aResult = (mDictionaryTable.GetEntry(aWord) || mIgnoreTable.GetEntry(aWord));
  *aResult = (mDictionaryTable.Contains(aWord) || mIgnoreTable.Contains(aWord));
  return NS_OK;
}

@@ -397,7 +386,7 @@ mozPersonalDictionary::AddWord(const nsAString& aWord) {
  nsresult res;
  WaitForLoad();

  mDictionaryTable.PutEntry(aWord);
  mDictionaryTable.Insert(aWord);
  res = Save();
  return res;
}
@@ -407,7 +396,7 @@ mozPersonalDictionary::RemoveWord(const nsAString& aWord) {
  nsresult res;
  WaitForLoad();

  mDictionaryTable.RemoveEntry(aWord);
  mDictionaryTable.Remove(aWord);
  res = Save();
  return res;
}
@@ -415,7 +404,7 @@ mozPersonalDictionary::RemoveWord(const nsAString& aWord) {
NS_IMETHODIMP
mozPersonalDictionary::IgnoreWord(const nsAString& aWord) {
  // avoid adding duplicate words to the ignore list
  if (!mIgnoreTable.GetEntry(aWord)) mIgnoreTable.PutEntry(aWord);
  mIgnoreTable.EnsureInserted(aWord);
  return NS_OK;
}

+3 −3
Original line number Diff line number Diff line
@@ -11,7 +11,7 @@
#include "mozIPersonalDictionary.h"
#include "nsIObserver.h"
#include "nsWeakReference.h"
#include "nsTHashtable.h"
#include "nsTHashSet.h"
#include "nsCRT.h"
#include "nsCycleCollectionParticipant.h"
#include "nsHashKeys.h"
@@ -53,8 +53,8 @@ class mozPersonalDictionary final : public mozIPersonalDictionary,
  nsCOMPtr<nsIFile> mFile;
  mozilla::Monitor mMonitor;
  mozilla::Monitor mMonitorSave;
  nsTHashtable<nsStringHashKey> mDictionaryTable;
  nsTHashtable<nsStringHashKey> mIgnoreTable;
  nsTHashSet<nsString> mDictionaryTable;
  nsTHashSet<nsString> mIgnoreTable;

 private:
  /* wait for the asynchronous load of the dictionary to be completed */
+2 −3
Original line number Diff line number Diff line
@@ -320,7 +320,7 @@ nsresult mozSpellChecker::GetDictionaryList(
  nsresult rv;

  // For catching duplicates
  nsTHashtable<nsCStringHashKey> dictionaries;
  nsTHashSet<nsCString> dictionaries;

  nsCOMArray<mozISpellCheckingEngine> spellCheckingEngines;
  rv = GetEngineList(&spellCheckingEngines);
@@ -334,9 +334,8 @@ nsresult mozSpellChecker::GetDictionaryList(
    for (auto& dictName : dictNames) {
      // Skip duplicate dictionaries. Only take the first one
      // for each name.
      if (dictionaries.Contains(dictName)) continue;
      if (!dictionaries.EnsureInserted(dictName)) continue;

      dictionaries.PutEntry(dictName);
      aDictionaryList->AppendElement(dictName);
    }
  }