diff options
author | limasdf <limasdf@gmail.com> | 2016-03-07 19:04:15 -0800 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2016-03-08 03:06:00 +0000 |
commit | 8477b57a78fa0faf4b0e65c3aaf6cd6f205fee28 (patch) | |
tree | 1d6ed9219cb3e61e152a6fbbb4a4ffa7c8d38139 /extensions/renderer | |
parent | 8ae69736414de22562db98323bf60f1b7339cccb (diff) | |
download | chromium_src-8477b57a78fa0faf4b0e65c3aaf6cd6f205fee28.zip chromium_src-8477b57a78fa0faf4b0e65c3aaf6cd6f205fee28.tar.gz chromium_src-8477b57a78fa0faf4b0e65c3aaf6cd6f205fee28.tar.bz2 |
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}
Diffstat (limited to 'extensions/renderer')
-rw-r--r-- | extensions/renderer/api_definitions_natives.cc | 12 | ||||
-rw-r--r-- | extensions/renderer/dispatcher.cc | 17 |
2 files changed, 10 insertions, 19 deletions
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<v8::Value>& args) { std::vector<std::string> apis; const FeatureProvider* feature_provider = FeatureProvider::GetAPIFeatures(); - const std::vector<std::string>& feature_names = - feature_provider->GetAllFeatureNames(); - for (std::vector<std::string>::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<std::string>& 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; } |