From 8477b57a78fa0faf4b0e65c3aaf6cd6f205fee28 Mon Sep 17 00:00:00 2001 From: limasdf Date: Mon, 7 Mar 2016 19:04:15 -0800 Subject: FeatureProvider returns std::map instead of vector To reduce binding time as much as possible, use std::map(O(1)) instead of std::vector(O(n)). Also, use 'const_iterator' to fix improper usage of 'auto'. BUG=592537 TEST=Every tests are green. Review URL: https://codereview.chromium.org/1772683002 Cr-Commit-Position: refs/heads/master@{#379711} --- extensions/renderer/api_definitions_natives.cc | 12 ++++-------- extensions/renderer/dispatcher.cc | 17 ++++++----------- 2 files changed, 10 insertions(+), 19 deletions(-) (limited to 'extensions/renderer') diff --git a/extensions/renderer/api_definitions_natives.cc b/extensions/renderer/api_definitions_natives.cc index 61ea710..96f1f2c 100644 --- a/extensions/renderer/api_definitions_natives.cc +++ b/extensions/renderer/api_definitions_natives.cc @@ -24,14 +24,10 @@ void ApiDefinitionsNatives::GetExtensionAPIDefinitionsForTest( const v8::FunctionCallbackInfo& args) { std::vector apis; const FeatureProvider* feature_provider = FeatureProvider::GetAPIFeatures(); - const std::vector& feature_names = - feature_provider->GetAllFeatureNames(); - for (std::vector::const_iterator i = feature_names.begin(); - i != feature_names.end(); - ++i) { - if (!feature_provider->GetParent(feature_provider->GetFeature(*i)) && - context()->GetAvailability(*i).is_available()) { - apis.push_back(*i); + for (const auto& map_entry : feature_provider->GetAllFeatures()) { + if (!feature_provider->GetParent(map_entry.second.get()) && + context()->GetAvailability(map_entry.first).is_available()) { + apis.push_back(map_entry.first); } } args.GetReturnValue().Set( diff --git a/extensions/renderer/dispatcher.cc b/extensions/renderer/dispatcher.cc index c3718d9..5ff2616e 100644 --- a/extensions/renderer/dispatcher.cc +++ b/extensions/renderer/dispatcher.cc @@ -1345,31 +1345,26 @@ void Dispatcher::UpdateBindingsForContext(ScriptContext* context) { // ones. const FeatureProvider* api_feature_provider = FeatureProvider::GetAPIFeatures(); - const std::vector& apis = - api_feature_provider->GetAllFeatureNames(); - for (const std::string& api_name : apis) { - Feature* feature = api_feature_provider->GetFeature(api_name); - DCHECK(feature); - + for (const auto& map_entry : api_feature_provider->GetAllFeatures()) { // Internal APIs are included via require(api_name) from internal code // rather than chrome[api_name]. - if (feature->IsInternal()) + if (map_entry.second->IsInternal()) continue; // If this API has a parent feature (and isn't marked 'noparent'), // then this must be a function or event, so we should not register. - if (api_feature_provider->GetParent(feature) != NULL) + if (api_feature_provider->GetParent(map_entry.second.get()) != nullptr) continue; // Skip chrome.test if this isn't a test. - if (api_name == "test" && + if (map_entry.first == "test" && !base::CommandLine::ForCurrentProcess()->HasSwitch( ::switches::kTestType)) { continue; } - if (context->IsAnyFeatureAvailableToContext(*feature)) - RegisterBinding(api_name, context); + if (context->IsAnyFeatureAvailableToContext(*map_entry.second.get())) + RegisterBinding(map_entry.first, context); } break; } -- cgit v1.1