Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(979)

Unified Diff: chrome/browser/spellchecker/spellcheck_custom_dictionary.cc

Issue 1665023002: Cheer up spell-checking code (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Reverted one auto Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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..17f8505bedac0c5bf449c1bcf8342e40b56a3213 100644
--- a/chrome/browser/spellchecker/spellcheck_custom_dictionary.cc
+++ b/chrome/browser/spellchecker/spellcheck_custom_dictionary.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Copyright 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -96,14 +96,14 @@ 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);
+ std::vector<std::string> new_words =
+ base::STLSetDifference<std::vector<std::string>>(*to_add, existing);
int result = VALID_CHANGE;
if (to_add->size() != new_words.size())
result |= DETECTED_DUPLICATE_WORDS;
// Do not add invalid words.
std::set<std::string> valid_new_words;
- for (const std::string& word : new_words) {
+ for (const auto& word : new_words) {
if (IsValidWord(word))
valid_new_words.insert(valid_new_words.end(), word);
}
@@ -333,16 +333,14 @@ syncer::SyncDataList SpellcheckCustomDictionary::GetAllSyncData(
DCHECK_CURRENTLY_ON(BrowserThread::UI);
DCHECK_EQ(syncer::DICTIONARY, type);
syncer::SyncDataList data;
- std::string word;
size_t i = 0;
- for (auto it = words_.begin();
- it != words_.end() &&
- i < chrome::spellcheck_common::MAX_SYNCABLE_DICTIONARY_WORDS;
- ++it, ++i) {
- word = *it;
+ for (const auto& word : words_) {
+ if (i >= chrome::spellcheck_common::MAX_SYNCABLE_DICTIONARY_WORDS)
groby-ooo-7-16 2016/02/09 20:20:26 Since this is purely a size limiter, just make it
Kevin Bailey 2016/02/09 22:26:39 Done.
+ break;
sync_pb::EntitySpecifics specifics;
specifics.mutable_dictionary()->set_word(word);
data.push_back(syncer::SyncData::CreateLocalData(word, word, specifics));
+ ++i;
}
return data;
}
@@ -445,12 +443,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);
}
void SpellcheckCustomDictionary::FixInvalidFile(
@@ -493,14 +487,15 @@ syncer::SyncError SpellcheckCustomDictionary::Sync(
syncer::SyncChangeList sync_change_list;
int i = 0;
- for (auto it = dictionary_change.to_add().begin();
- it != dictionary_change.to_add().end() && i < upload_size; ++it, ++i) {
- const std::string& word = *it;
+ for (const auto& word : dictionary_change.to_add()) {
+ if (i >= upload_size)
+ break;
sync_pb::EntitySpecifics specifics;
specifics.mutable_dictionary()->set_word(word);
sync_change_list.push_back(syncer::SyncChange(
FROM_HERE, syncer::SyncChange::ACTION_ADD,
syncer::SyncData::CreateLocalData(word, word, specifics)));
+ ++i;
groby-ooo-7-16 2016/02/09 20:20:26 See above.
Kevin Bailey 2016/02/09 22:26:39 Done.
}
for (const std::string& word : dictionary_change.to_remove()) {
« chrome/browser/spellchecker/feedback_sender.cc ('K') | « chrome/browser/spellchecker/misspelling.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698