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

Unified Diff: components/omnibox/browser/url_index_private_data.cc

Issue 2719403002: Switching to flat_sets in HQP. (Closed)
Patch Set: Review, round 1. Created 3 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
« no previous file with comments | « components/omnibox/browser/in_memory_url_index_types.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: components/omnibox/browser/url_index_private_data.cc
diff --git a/components/omnibox/browser/url_index_private_data.cc b/components/omnibox/browser/url_index_private_data.cc
index e410239b77e325f7a26624c8157e7be42b777255..63b41107439cb8f2f80fd71d3a0a913e6286fac4 100644
--- a/components/omnibox/browser/url_index_private_data.cc
+++ b/components/omnibox/browser/url_index_private_data.cc
@@ -483,12 +483,10 @@ HistoryIDVector URLIndexPrivateData::HistoryIDsFromWords(
// TODO(dyaroshev): write a generic algorithm(crbug.com/696167).
for (String16Vector::iterator iter = words.begin(); iter != words.end();
++iter) {
- base::string16 uni_word = *iter;
- HistoryIDSet term_history_set = HistoryIDsForTerm(uni_word);
- if (term_history_set.empty()) {
- history_ids.clear();
- break;
- }
+ HistoryIDSet term_history_set = HistoryIDsForTerm(*iter);
+ if (term_history_set.empty())
+ return HistoryIDVector();
+
if (iter == words.begin()) {
history_ids = {term_history_set.begin(), term_history_set.end()};
} else {
@@ -588,28 +586,30 @@ HistoryIDSet URLIndexPrivateData::HistoryIDsForTerm(
// We must filter the word list because the resulting word set surely
// contains words which do not have the search term as a proper subset.
- for (WordIDSet::iterator word_set_iter = word_id_set.begin();
- word_set_iter != word_id_set.end(); ) {
- if (word_list_[*word_set_iter].find(term) == base::string16::npos)
- word_set_iter = word_id_set.erase(word_set_iter);
- else
- ++word_set_iter;
- }
+ word_id_set.erase(std::remove_if(word_id_set.begin(), word_id_set.end(),
+ [&](WordID word_id) {
+ return word_list_[word_id].find(term) ==
+ base::string16::npos;
+ }),
+ word_id_set.end());
} else {
word_id_set = WordIDSetForTermChars(Char16SetFromString16(term));
}
// If any words resulted then we can compose a set of history IDs by unioning
// the sets from each word.
- HistoryIDSet history_id_set;
+ // We use |buffer| because it's more efficient to collect everything and then
+ // construct a flat_set than to insert elements one by one.
+ HistoryIDVector buffer;
for (WordID word_id : word_id_set) {
WordIDHistoryMap::iterator word_iter = word_id_history_map_.find(word_id);
if (word_iter != word_id_history_map_.end()) {
HistoryIDSet& word_history_id_set(word_iter->second);
- history_id_set.insert(word_history_id_set.begin(),
- word_history_id_set.end());
+ buffer.insert(buffer.end(), word_history_id_set.begin(),
+ word_history_id_set.end());
}
}
+ HistoryIDSet history_id_set(buffer.begin(), buffer.end());
// Record a new cache entry for this word if the term is longer than
// a single character.
@@ -627,24 +627,19 @@ WordIDSet URLIndexPrivateData::WordIDSetForTermChars(
for (Char16Set::const_iterator c_iter = term_chars.begin();
c_iter != term_chars.end(); ++c_iter) {
CharWordIDMap::iterator char_iter = char_word_map_.find(*c_iter);
- if (char_iter == char_word_map_.end()) {
- // A character was not found so there are no matching results: bail.
- word_id_set.clear();
- break;
- }
- WordIDSet& char_word_id_set(char_iter->second);
+ // A character was not found so there are no matching results: bail.
+ if (char_iter == char_word_map_.end())
+ return WordIDSet();
+
+ const WordIDSet& char_word_id_set(char_iter->second);
// It is possible for there to no longer be any words associated with
// a particular character. Give up in that case.
- if (char_word_id_set.empty()) {
- word_id_set.clear();
- break;
- }
+ if (char_word_id_set.empty())
+ return WordIDSet();
if (c_iter == term_chars.begin()) {
- // First character results becomes base set of results.
word_id_set = char_word_id_set;
} else {
- // Subsequent character results get intersected in.
word_id_set =
base::STLSetIntersection<WordIDSet>(word_id_set, char_word_id_set);
}
@@ -709,7 +704,7 @@ void URLIndexPrivateData::HistoryIdsToScoredMatches(
num_matches, now);
// Filter new matches that ended up scoring 0. (These are usually matches
// which didn't match the user's raw terms.)
- if (new_scored_match.raw_score != 0)
+ if (new_scored_match.raw_score > 0)
scored_items->push_back(std::move(new_scored_match));
}
}
« no previous file with comments | « components/omnibox/browser/in_memory_url_index_types.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698