Chromium Code Reviews| Index: chrome/browser/spellchecker/spellcheck_custom_dictionary.cc |
| diff --git a/chrome/browser/spellchecker/spellcheck_custom_dictionary.cc b/chrome/browser/spellchecker/spellcheck_custom_dictionary.cc |
| index c9d113fd6025caf53e4ccf184a5626712bff11f2..bb46fb4490d690fde1f75cff49c5a8ca1480f4dc 100644 |
| --- a/chrome/browser/spellchecker/spellcheck_custom_dictionary.cc |
| +++ b/chrome/browser/spellchecker/spellcheck_custom_dictionary.cc |
| @@ -14,6 +14,7 @@ |
| #include "base/strings/string_number_conversions.h" |
| #include "base/strings/string_split.h" |
| #include "base/strings/string_util.h" |
| +#include "chrome/browser/spellchecker/set_difference_container.h" |
| #include "chrome/browser/spellchecker/spellcheck_host_metrics.h" |
| #include "chrome/common/chrome_constants.h" |
| #include "chrome/common/spellcheck_common.h" |
| @@ -96,18 +97,21 @@ int SanitizeWordsToAdd(const std::set<std::string>& existing, |
| std::set<std::string>* to_add) { |
| DCHECK(to_add); |
| // Do not add duplicate words. |
| - std::set<std::string> new_words = |
| - base::STLSetDifference<std::set<std::string>>(*to_add, existing); |
| + spellcheck::set_difference_container<std::set<std::string>, |
| + std::set<std::string> > |
|
please use gerrit instead
2016/02/03 23:59:11
No space inside of ">>".
Kevin Bailey
2016/02/04 16:34:12
Done.
|
| + new_words(*to_add, existing); |
| int result = VALID_CHANGE; |
| - if (to_add->size() != new_words.size()) |
| - result |= DETECTED_DUPLICATE_WORDS; |
| + unsigned new_words_size = 0; |
|
please use gerrit instead
2016/02/03 23:59:11
size_t, since we're comparing it to std::set::size
Kevin Bailey
2016/02/04 16:34:12
If true, the unsigned would be promoted. I think y
groby-ooo-7-16
2016/02/04 19:38:36
We're trying to avoid implicit promotions.
Quoth
|
| // Do not add invalid words. |
| std::set<std::string> valid_new_words; |
| for (const std::string& word : new_words) { |
| + ++new_words_size; |
| if (IsValidWord(word)) |
| valid_new_words.insert(valid_new_words.end(), word); |
| } |
| - if (valid_new_words.size() != new_words.size()) |
| + if (to_add->size() != new_words_size) |
| + result |= DETECTED_DUPLICATE_WORDS; |
| + if (valid_new_words.size() != new_words_size) |
| result |= DETECTED_INVALID_WORDS; |
| // Save the sanitized words to be added. |
| std::swap(*to_add, valid_new_words); |
| @@ -445,12 +449,8 @@ void SpellcheckCustomDictionary::Apply(const Change& dictionary_change) { |
| words_.insert(dictionary_change.to_add().begin(), |
| dictionary_change.to_add().end()); |
| } |
| - if (!dictionary_change.to_remove().empty()) { |
| - std::set<std::string> updated_words = |
| - base::STLSetDifference<std::set<std::string>>( |
| - words_, dictionary_change.to_remove()); |
| - std::swap(words_, updated_words); |
| - } |
| + for (const auto& word : dictionary_change.to_remove()) |
| + words_.erase(word); |
|
please use gerrit instead
2016/02/03 23:59:11
Let's not switch this algorithm, because it's O(n*
Kevin Bailey
2016/02/04 16:34:12
The old one is very O(n ln(n)). :) Consider:
line
groby-ooo-7-16
2016/02/04 19:38:36
Even if it were an O(n) vs O(n ln n) difference -
|
| } |
| void SpellcheckCustomDictionary::FixInvalidFile( |