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

Unified Diff: ui/app_list/search/mixer.cc

Issue 2701123002: AppList Performance Optimization 2 (Closed)
Patch Set: Cache the tokenized name 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
Index: ui/app_list/search/mixer.cc
diff --git a/ui/app_list/search/mixer.cc b/ui/app_list/search/mixer.cc
index 0e8cdb33e00ed17b979d39ed499f39db425ea793..78db4de53756c8dae7b7a17c6e5c776e3055460d 100644
--- a/ui/app_list/search/mixer.cc
+++ b/ui/app_list/search/mixer.cc
@@ -28,8 +28,7 @@ void UpdateResult(const SearchResult& source, SearchResult* target) {
} // namespace
-Mixer::SortData::SortData() : result(NULL), score(0.0) {
-}
+Mixer::SortData::SortData() : result(nullptr), score(0.0) {}
Mixer::SortData::SortData(SearchResult* result, double score)
: result(result), score(score) {
@@ -47,21 +46,22 @@ class Mixer::Group {
: max_results_(max_results), multiplier_(multiplier) {}
~Group() {}
- void AddProvider(SearchProvider* provider) { providers_.push_back(provider); }
+ void AddProvider(SearchProvider* provider) {
+ providers_.emplace_back(provider);
+ }
void FetchResults(bool is_voice_query, const KnownResults& known_results) {
results_.clear();
for (const SearchProvider* provider : providers_) {
- for (SearchResult* result : provider->results()) {
+ for (const auto& result : provider->results()) {
DCHECK(!result->id().empty());
// We cannot rely on providers to give relevance scores in the range
// [0.0, 1.0] (e.g., PeopleProvider directly gives values from the
// Google+ API). Clamp to that range.
- double relevance = std::min(std::max(result->relevance(), 0.0), 1.0);
-
- double multiplier = multiplier_;
+ const double relevance =
+ std::min(std::max(result->relevance(), 0.0), 1.0);
double boost = 0.0;
// Recommendations should not be affected by query-to-launch correlation
@@ -97,7 +97,7 @@ class Mixer::Group {
boost += 4.0;
}
- results_.push_back(SortData(result, relevance * multiplier + boost));
+ results_.emplace_back(result.get(), relevance * multiplier_ + boost);
}
}
@@ -145,7 +145,7 @@ void Mixer::MixAndPublish(bool is_voice_query,
// Add results from each group. Limit to the maximum number of results in each
// group.
for (const Group* group : groups_) {
- size_t num_results =
+ const size_t num_results =
std::min(group->results().size(), group->max_results());
results.insert(results.end(), group->results().begin(),
group->results().begin() + num_results);
@@ -157,8 +157,8 @@ void Mixer::MixAndPublish(bool is_voice_query,
RemoveDuplicates(&results);
std::sort(results.begin(), results.end());
- if (results.size() < num_max_results) {
- size_t original_size = results.size();
+ const size_t original_size = results.size();
+ if (original_size < num_max_results) {
// We didn't get enough results. Insert all the results again, and this
// time, do not limit the maximum number of results from each group. (This
// will result in duplicates, which will be removed by RemoveDuplicates.)
@@ -192,7 +192,7 @@ void Mixer::Publish(const SortedResults& new_results,
// meaningful indexes.
auto current_results = ui_results->RemoveAll();
std::map<std::string, std::unique_ptr<SearchResult>> ui_results_map;
- for (std::unique_ptr<SearchResult>& ui_result : current_results)
+ for (auto& ui_result : current_results)
ui_results_map[ui_result->id()] = std::move(ui_result);
// Add items back to |ui_results| in the order of |new_results|.
@@ -227,12 +227,10 @@ void Mixer::RemoveDuplicates(SortedResults* results) {
std::set<std::string> id_set;
for (const SortData& sort_data : *results) {
- const std::string& id = sort_data.result->id();
- if (id_set.find(id) != id_set.end())
+ if (!id_set.insert(sort_data.result->id()).second)
continue;
- id_set.insert(id);
- final.push_back(sort_data);
+ final.emplace_back(sort_data);
}
results->swap(final);
« no previous file with comments | « chrome/browser/ui/app_list/search/webstore/webstore_provider_browsertest.cc ('k') | ui/app_list/search/tokenized_string.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698