| Index: chrome/renderer/spellchecker/hunspell_engine.cc
|
| diff --git a/chrome/renderer/spellchecker/hunspell_engine.cc b/chrome/renderer/spellchecker/hunspell_engine.cc
|
| index 71a14d2d5228c9cb54f5f0eceb92a77bdf98ed91..dde2db598d0997bf8c337b8e9b7f2d7a885cac83 100644
|
| --- a/chrome/renderer/spellchecker/hunspell_engine.cc
|
| +++ b/chrome/renderer/spellchecker/hunspell_engine.cc
|
| @@ -4,6 +4,9 @@
|
|
|
| #include "hunspell_engine.h"
|
|
|
| +#include <algorithm>
|
| +#include <iterator>
|
| +
|
| #include "base/metrics/histogram.h"
|
| #include "base/time.h"
|
| #include "chrome/common/spellcheck_common.h"
|
| @@ -56,9 +59,7 @@ void HunspellEngine::InitializeHunspell() {
|
| new Hunspell(bdict_file_->data(), bdict_file_->length()));
|
|
|
| // Add custom words to Hunspell.
|
| - chrome::spellcheck_common::WordList::iterator it;
|
| - for (it = custom_words_.begin(); it != custom_words_.end(); ++it)
|
| - AddWordToHunspell(*it);
|
| + AddWordsToHunspell(custom_words_);
|
|
|
| DHISTOGRAM_TIMES("Spellcheck.InitTime",
|
| base::Histogram::DebugNow() - debug_start_time);
|
| @@ -67,14 +68,27 @@ void HunspellEngine::InitializeHunspell() {
|
| }
|
| }
|
|
|
| -void HunspellEngine::AddWordToHunspell(const std::string& word) {
|
| - if (!word.empty() && word.length() < MAXWORDLEN)
|
| - hunspell_->add(word.c_str());
|
| +void HunspellEngine::AddWordsToHunspell(const std::vector<std::string>& words) {
|
| + std::string word;
|
| + for (chrome::spellcheck_common::WordList::const_iterator it = words.begin();
|
| + it != words.end();
|
| + ++it) {
|
| + word = *it;
|
| + if (!word.empty() && word.length() < MAXWORDLEN)
|
| + hunspell_->add(word.c_str());
|
| + }
|
| }
|
|
|
| -void HunspellEngine::RemoveWordFromHunspell(const std::string& word) {
|
| - if (!word.empty() && word.length() < MAXWORDLEN)
|
| - hunspell_->remove(word.c_str());
|
| +void HunspellEngine::RemoveWordsFromHunspell(
|
| + const std::vector<std::string>& words) {
|
| + std::string word;
|
| + for (std::vector<std::string>::const_iterator it = words.begin();
|
| + it != words.end();
|
| + ++it) {
|
| + word = *it;
|
| + if (!word.empty() && word.length() < MAXWORDLEN)
|
| + hunspell_->remove(word.c_str());
|
| + }
|
| }
|
|
|
| bool HunspellEngine::CheckSpelling(const string16& word_to_check, int tag) {
|
| @@ -84,7 +98,7 @@ bool HunspellEngine::CheckSpelling(const string16& word_to_check, int tag) {
|
| if (word_to_check_utf8.length() < MAXWORDLEN) {
|
| if (hunspell_.get()) {
|
| // |hunspell_->spell| returns 0 if the word is spelled correctly and
|
| - // non-zero otherwsie.
|
| + // non-zero otherwise.
|
| word_correct = (hunspell_->spell(word_to_check_utf8.c_str()) != 0);
|
| } else {
|
| // If |hunspell_| is NULL here, an error has occurred, but it's better
|
| @@ -119,23 +133,28 @@ void HunspellEngine::FillSuggestionList(
|
| free(suggestions);
|
| }
|
|
|
| -void HunspellEngine::OnWordAdded(const std::string& word) {
|
| +void HunspellEngine::OnWordsAddedRemoved(
|
| + const std::vector<std::string>& words_added,
|
| + const std::vector<std::string>& words_removed) {
|
| if (!hunspell_.get()) {
|
| // Save it for later---add it when hunspell is initialized.
|
| - custom_words_.push_back(word);
|
| - } else {
|
| - AddWordToHunspell(word);
|
| - }
|
| -}
|
| -
|
| -void HunspellEngine::OnWordRemoved(const std::string& word) {
|
| - if (!hunspell_.get()) {
|
| - chrome::spellcheck_common::WordList::iterator it = std::find(
|
| - custom_words_.begin(), custom_words_.end(), word);
|
| - if (it != custom_words_.end())
|
| - custom_words_.erase(it);
|
| + custom_words_.insert(custom_words_.end(),
|
| + words_added.begin(),
|
| + words_added.end());
|
| + // Remove words.
|
| + std::vector<std::string> words_removed_copy(words_removed);
|
| + std::sort(words_removed_copy.begin(), words_removed_copy.end());
|
| + std::sort(custom_words_.begin(), custom_words_.end());
|
| + std::vector<std::string> updated_custom_words;
|
| + std::set_difference(custom_words_.begin(),
|
| + custom_words_.end(),
|
| + words_removed_copy.begin(),
|
| + words_removed_copy.end(),
|
| + std::back_inserter(updated_custom_words));
|
| + std::swap(custom_words_, updated_custom_words);
|
| } else {
|
| - RemoveWordFromHunspell(word);
|
| + AddWordsToHunspell(words_added);
|
| + RemoveWordsFromHunspell(words_removed);
|
| }
|
| }
|
|
|
|
|