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

Unified Diff: components/safe_browsing_db/remote_database_manager.cc

Issue 2838163002: Use base::flat_set<> rather than std::set<> for ResourceType set (Closed)
Patch Set: Created 3 years, 8 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/safe_browsing_db/remote_database_manager.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: components/safe_browsing_db/remote_database_manager.cc
diff --git a/components/safe_browsing_db/remote_database_manager.cc b/components/safe_browsing_db/remote_database_manager.cc
index 2def386d5f8b885838ebcc49de2cc136c07e5532..3c4ec552c46b33fbbcdff8e8c80ef198b06e4136 100644
--- a/components/safe_browsing_db/remote_database_manager.cc
+++ b/components/safe_browsing_db/remote_database_manager.cc
@@ -99,9 +99,12 @@ void RemoteSafeBrowsingDatabaseManager::ClientRequest::OnRequestDone(
// TODO(nparker): Add more tests for this class
RemoteSafeBrowsingDatabaseManager::RemoteSafeBrowsingDatabaseManager() {
+ // Adding one element at a time to a base::flat_set is inefficient. Creating
+ // the list of elements in a vector first avoids extra allocations.
+ std::vector<content::ResourceType> types_to_check;
Nathan Parker 2017/04/25 15:23:14 This seems seems like overkill for 18 elements tha
Adam Rice 2017/04/26 05:18:27 I've tried adding directly to the set in patch set
// Decide which resource types to check. These two are the minimum.
- resource_types_to_check_.insert(content::RESOURCE_TYPE_MAIN_FRAME);
- resource_types_to_check_.insert(content::RESOURCE_TYPE_SUB_FRAME);
+ types_to_check.push_back(content::RESOURCE_TYPE_MAIN_FRAME);
+ types_to_check.push_back(content::RESOURCE_TYPE_SUB_FRAME);
// The param is expected to be a comma-separated list of ints
// corresponding to the enum types. We're keeping this finch
@@ -122,7 +125,7 @@ RemoteSafeBrowsingDatabaseManager::RemoteSafeBrowsingDatabaseManager() {
case content::RESOURCE_TYPE_FAVICON:
break;
default:
- resource_types_to_check_.insert(t);
+ types_to_check.push_back(t);
}
}
} else {
@@ -132,10 +135,13 @@ RemoteSafeBrowsingDatabaseManager::RemoteSafeBrowsingDatabaseManager() {
int i;
if (base::StringToInt(val_str, &i) && i >= 0 &&
i < content::RESOURCE_TYPE_LAST_TYPE) {
- resource_types_to_check_.insert(static_cast<content::ResourceType>(i));
+ types_to_check.push_back(static_cast<content::ResourceType>(i));
}
}
}
+ base::flat_set<content::ResourceType> resource_types_to_check_temporary(
+ std::move(types_to_check), base::KEEP_FIRST_OF_DUPES);
+ resource_types_to_check_.swap(resource_types_to_check_temporary);
}
RemoteSafeBrowsingDatabaseManager::~RemoteSafeBrowsingDatabaseManager() {
« no previous file with comments | « components/safe_browsing_db/remote_database_manager.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698