OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "components/omnibox/browser/url_index_private_data.h" | 5 #include "components/omnibox/browser/url_index_private_data.h" |
6 | 6 |
7 #include <stdint.h> | 7 #include <stdint.h> |
8 | 8 |
9 #include <functional> | 9 #include <functional> |
10 #include <iterator> | 10 #include <iterator> |
(...skipping 260 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
271 } | 271 } |
272 post_scoring_item_count_ = scored_items.size(); | 272 post_scoring_item_count_ = scored_items.size(); |
273 | 273 |
274 if (was_trimmed) { | 274 if (was_trimmed) { |
275 search_term_cache_.clear(); // Invalidate the term cache. | 275 search_term_cache_.clear(); // Invalidate the term cache. |
276 } else { | 276 } else { |
277 // Remove any stale SearchTermCacheItems. | 277 // Remove any stale SearchTermCacheItems. |
278 for (SearchTermCacheMap::iterator cache_iter = search_term_cache_.begin(); | 278 for (SearchTermCacheMap::iterator cache_iter = search_term_cache_.begin(); |
279 cache_iter != search_term_cache_.end(); ) { | 279 cache_iter != search_term_cache_.end(); ) { |
280 if (!cache_iter->second.used_) | 280 if (!cache_iter->second.used_) |
281 search_term_cache_.erase(cache_iter++); | 281 cache_iter = search_term_cache_.erase(cache_iter); |
282 else | 282 else |
283 ++cache_iter; | 283 ++cache_iter; |
284 } | 284 } |
285 } | 285 } |
286 | 286 |
287 return scored_items; | 287 return scored_items; |
288 } | 288 } |
289 | 289 |
290 bool URLIndexPrivateData::UpdateURL( | 290 bool URLIndexPrivateData::UpdateURL( |
291 history::HistoryService* history_service, | 291 history::HistoryService* history_service, |
(...skipping 331 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
623 word_id_set, leftover_set); | 623 word_id_set, leftover_set); |
624 word_id_set.swap(new_word_id_set); | 624 word_id_set.swap(new_word_id_set); |
625 } | 625 } |
626 } | 626 } |
627 | 627 |
628 // We must filter the word list because the resulting word set surely | 628 // We must filter the word list because the resulting word set surely |
629 // contains words which do not have the search term as a proper subset. | 629 // contains words which do not have the search term as a proper subset. |
630 for (WordIDSet::iterator word_set_iter = word_id_set.begin(); | 630 for (WordIDSet::iterator word_set_iter = word_id_set.begin(); |
631 word_set_iter != word_id_set.end(); ) { | 631 word_set_iter != word_id_set.end(); ) { |
632 if (word_list_[*word_set_iter].find(term) == base::string16::npos) | 632 if (word_list_[*word_set_iter].find(term) == base::string16::npos) |
633 word_id_set.erase(word_set_iter++); | 633 word_set_iter = word_id_set.erase(word_set_iter); |
634 else | 634 else |
635 ++word_set_iter; | 635 ++word_set_iter; |
636 } | 636 } |
637 } else { | 637 } else { |
638 word_id_set = WordIDSetForTermChars(Char16SetFromString16(term)); | 638 word_id_set = WordIDSetForTermChars(Char16SetFromString16(term)); |
639 } | 639 } |
640 | 640 |
641 // If any words resulted then we can compose a set of history IDs by unioning | 641 // If any words resulted then we can compose a set of history IDs by unioning |
642 // the sets from each word. | 642 // the sets from each word. |
643 HistoryIDSet history_id_set; | 643 HistoryIDSet history_id_set; |
644 if (!word_id_set.empty()) { | 644 if (!word_id_set.empty()) { |
645 auto unsafe = history_id_set.unsafe_access(); | |
dyaroshev
2016/09/13 12:28:13
Here is the tight spot I was talking about in chro
| |
645 for (WordIDSet::iterator word_id_iter = word_id_set.begin(); | 646 for (WordIDSet::iterator word_id_iter = word_id_set.begin(); |
646 word_id_iter != word_id_set.end(); ++word_id_iter) { | 647 word_id_iter != word_id_set.end(); ++word_id_iter) { |
647 WordID word_id = *word_id_iter; | 648 WordID word_id = *word_id_iter; |
648 WordIDHistoryMap::iterator word_iter = word_id_history_map_.find(word_id); | 649 WordIDHistoryMap::iterator word_iter = word_id_history_map_.find(word_id); |
649 if (word_iter != word_id_history_map_.end()) { | 650 if (word_iter != word_id_history_map_.end()) { |
650 HistoryIDSet& word_history_id_set(word_iter->second); | 651 HistoryIDSet& word_history_id_set(word_iter->second); |
651 history_id_set.insert(word_history_id_set.begin(), | 652 unsafe->insert(unsafe->end(), word_history_id_set.begin(), |
652 word_history_id_set.end()); | 653 word_history_id_set.end()); |
653 } | 654 } |
654 } | 655 } |
655 } | 656 } |
656 | 657 |
657 // Record a new cache entry for this word if the term is longer than | 658 // Record a new cache entry for this word if the term is longer than |
658 // a single character. | 659 // a single character. |
659 if (term_length > 1) | 660 if (term_length > 1) |
660 search_term_cache_[term] = SearchTermCacheItem(word_id_set, history_id_set); | 661 search_term_cache_[term] = SearchTermCacheItem(word_id_set, history_id_set); |
661 | 662 |
662 return history_id_set; | 663 return history_id_set; |
(...skipping 691 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1354 // First cut: typed count, visit count, recency. | 1355 // First cut: typed count, visit count, recency. |
1355 // TODO(mrossetti): This is too simplistic. Consider an approach which ranks | 1356 // TODO(mrossetti): This is too simplistic. Consider an approach which ranks |
1356 // recently visited (within the last 12/24 hours) as highly important. Get | 1357 // recently visited (within the last 12/24 hours) as highly important. Get |
1357 // input from mpearson. | 1358 // input from mpearson. |
1358 if (r1.typed_count() != r2.typed_count()) | 1359 if (r1.typed_count() != r2.typed_count()) |
1359 return (r1.typed_count() > r2.typed_count()); | 1360 return (r1.typed_count() > r2.typed_count()); |
1360 if (r1.visit_count() != r2.visit_count()) | 1361 if (r1.visit_count() != r2.visit_count()) |
1361 return (r1.visit_count() > r2.visit_count()); | 1362 return (r1.visit_count() > r2.visit_count()); |
1362 return (r1.last_visit() > r2.last_visit()); | 1363 return (r1.last_visit() > r2.last_visit()); |
1363 } | 1364 } |
OLD | NEW |