Chromium Code Reviews| 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() { |