Commit 7e90bf80 authored by Sophie Chang's avatar Sophie Chang Committed by Commit Bot

Move away from unordered maps and sets in optimization guide code

Bug: 1007374
Change-Id: I1fd66d8f351ac1191aa42688f8fed39a347ce06b
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1836432
Commit-Queue: Sophie Chang <sophiechang@chromium.org>
Reviewed-by: default avatarTarun Bansal <tbansal@chromium.org>
Cr-Commit-Position: refs/heads/master@{#702335}
parent 9a5c75e7
...@@ -250,7 +250,7 @@ void OptimizationGuideHintsManager::OnHintsComponentAvailable( ...@@ -250,7 +250,7 @@ void OptimizationGuideHintsManager::OnHintsComponentAvailable(
std::unique_ptr<optimization_guide::HintUpdateData> std::unique_ptr<optimization_guide::HintUpdateData>
OptimizationGuideHintsManager::ProcessHintsComponent( OptimizationGuideHintsManager::ProcessHintsComponent(
const optimization_guide::HintsComponentInfo& info, const optimization_guide::HintsComponentInfo& info,
const std::unordered_set<optimization_guide::proto::OptimizationType>& const base::flat_set<optimization_guide::proto::OptimizationType>&
registered_optimization_types, registered_optimization_types,
std::unique_ptr<optimization_guide::HintUpdateData> update_data) { std::unique_ptr<optimization_guide::HintUpdateData> update_data) {
DCHECK(background_task_runner_->RunsTasksInCurrentSequence()); DCHECK(background_task_runner_->RunsTasksInCurrentSequence());
...@@ -287,7 +287,7 @@ void OptimizationGuideHintsManager::ProcessOptimizationFilters( ...@@ -287,7 +287,7 @@ void OptimizationGuideHintsManager::ProcessOptimizationFilters(
const google::protobuf::RepeatedPtrField< const google::protobuf::RepeatedPtrField<
optimization_guide::proto::OptimizationFilter>& optimization_guide::proto::OptimizationFilter>&
blacklist_optimization_filters, blacklist_optimization_filters,
const std::unordered_set<optimization_guide::proto::OptimizationType>& const base::flat_set<optimization_guide::proto::OptimizationType>&
registered_optimization_types) { registered_optimization_types) {
DCHECK(background_task_runner_->RunsTasksInCurrentSequence()); DCHECK(background_task_runner_->RunsTasksInCurrentSequence());
base::AutoLock lock(optimization_filters_lock_); base::AutoLock lock(optimization_filters_lock_);
......
...@@ -6,11 +6,11 @@ ...@@ -6,11 +6,11 @@
#define CHROME_BROWSER_OPTIMIZATION_GUIDE_OPTIMIZATION_GUIDE_HINTS_MANAGER_H_ #define CHROME_BROWSER_OPTIMIZATION_GUIDE_OPTIMIZATION_GUIDE_HINTS_MANAGER_H_
#include <memory> #include <memory>
#include <unordered_map>
#include <unordered_set>
#include <vector> #include <vector>
#include "base/callback_forward.h" #include "base/callback_forward.h"
#include "base/containers/flat_map.h"
#include "base/containers/flat_set.h"
#include "base/memory/scoped_refptr.h" #include "base/memory/scoped_refptr.h"
#include "base/memory/weak_ptr.h" #include "base/memory/weak_ptr.h"
#include "base/optional.h" #include "base/optional.h"
...@@ -145,7 +145,7 @@ class OptimizationGuideHintsManager ...@@ -145,7 +145,7 @@ class OptimizationGuideHintsManager
// |background_task_runner_|. // |background_task_runner_|.
std::unique_ptr<optimization_guide::HintUpdateData> ProcessHintsComponent( std::unique_ptr<optimization_guide::HintUpdateData> ProcessHintsComponent(
const optimization_guide::HintsComponentInfo& info, const optimization_guide::HintsComponentInfo& info,
const std::unordered_set<optimization_guide::proto::OptimizationType>& const base::flat_set<optimization_guide::proto::OptimizationType>&
registered_optimization_types, registered_optimization_types,
std::unique_ptr<optimization_guide::HintUpdateData> update_data); std::unique_ptr<optimization_guide::HintUpdateData> update_data);
...@@ -157,7 +157,7 @@ class OptimizationGuideHintsManager ...@@ -157,7 +157,7 @@ class OptimizationGuideHintsManager
const google::protobuf::RepeatedPtrField< const google::protobuf::RepeatedPtrField<
optimization_guide::proto::OptimizationFilter>& optimization_guide::proto::OptimizationFilter>&
blacklist_optimization_filters, blacklist_optimization_filters,
const std::unordered_set<optimization_guide::proto::OptimizationType>& const base::flat_set<optimization_guide::proto::OptimizationType>&
registered_optimization_types); registered_optimization_types);
// Callback run after the hint cache is fully initialized. At this point, the // Callback run after the hint cache is fully initialized. At this point, the
...@@ -258,7 +258,7 @@ class OptimizationGuideHintsManager ...@@ -258,7 +258,7 @@ class OptimizationGuideHintsManager
// manager. // manager.
// //
// Should only be read and modified on the UI thread. // Should only be read and modified on the UI thread.
std::unordered_set<optimization_guide::proto::OptimizationType> base::flat_set<optimization_guide::proto::OptimizationType>
registered_optimization_types_; registered_optimization_types_;
// Synchronizes access to member variables related to optimization filters. // Synchronizes access to member variables related to optimization filters.
...@@ -266,13 +266,13 @@ class OptimizationGuideHintsManager ...@@ -266,13 +266,13 @@ class OptimizationGuideHintsManager
// The set of optimization types that the component specified by // The set of optimization types that the component specified by
// |component_info_| has optimization filters for. // |component_info_| has optimization filters for.
std::unordered_set<optimization_guide::proto::OptimizationType> base::flat_set<optimization_guide::proto::OptimizationType>
optimization_types_with_filter_ GUARDED_BY(optimization_filters_lock_); optimization_types_with_filter_ GUARDED_BY(optimization_filters_lock_);
// A map from optimization type to the host filter that holds the blacklist // A map from optimization type to the host filter that holds the blacklist
// for that type. // for that type.
std::unordered_map<optimization_guide::proto::OptimizationType, base::flat_map<optimization_guide::proto::OptimizationType,
std::unique_ptr<optimization_guide::OptimizationFilter>> std::unique_ptr<optimization_guide::OptimizationFilter>>
blacklist_optimization_filters_ GUARDED_BY(optimization_filters_lock_); blacklist_optimization_filters_ GUARDED_BY(optimization_filters_lock_);
// Background thread where hints processing should be performed. // Background thread where hints processing should be performed.
......
...@@ -6,7 +6,6 @@ ...@@ -6,7 +6,6 @@
#define CHROME_BROWSER_OPTIMIZATION_GUIDE_OPTIMIZATION_GUIDE_KEYED_SERVICE_H_ #define CHROME_BROWSER_OPTIMIZATION_GUIDE_OPTIMIZATION_GUIDE_KEYED_SERVICE_H_
#include <memory> #include <memory>
#include <unordered_set>
#include <vector> #include <vector>
#include "base/macros.h" #include "base/macros.h"
......
...@@ -8,9 +8,9 @@ ...@@ -8,9 +8,9 @@
#include <stdint.h> #include <stdint.h>
#include <memory> #include <memory>
#include <string> #include <string>
#include <unordered_map>
#include <utility> #include <utility>
#include "base/containers/flat_map.h"
#include "base/optional.h" #include "base/optional.h"
#include "components/optimization_guide/optimization_guide_decider.h" #include "components/optimization_guide/optimization_guide_decider.h"
#include "components/optimization_guide/optimization_guide_enums.h" #include "components/optimization_guide/optimization_guide_enums.h"
...@@ -118,13 +118,13 @@ class OptimizationGuideNavigationData { ...@@ -118,13 +118,13 @@ class OptimizationGuideNavigationData {
base::Optional<std::string> serialized_hint_version_string_; base::Optional<std::string> serialized_hint_version_string_;
// The map from optimization type to the last decision made for that type. // The map from optimization type to the last decision made for that type.
std::unordered_map<optimization_guide::proto::OptimizationType, base::flat_map<optimization_guide::proto::OptimizationType,
optimization_guide::OptimizationTypeDecision> optimization_guide::OptimizationTypeDecision>
optimization_type_decisions_; optimization_type_decisions_;
// The map from optimization target to the last decision made for that target. // The map from optimization target to the last decision made for that target.
std::unordered_map<optimization_guide::proto::OptimizationTarget, base::flat_map<optimization_guide::proto::OptimizationTarget,
optimization_guide::OptimizationTargetDecision> optimization_guide::OptimizationTargetDecision>
optimization_target_decisions_; optimization_target_decisions_;
// Whether the hint cache had a hint for the navigation before commit. // Whether the hint cache had a hint for the navigation before commit.
......
...@@ -5,8 +5,8 @@ ...@@ -5,8 +5,8 @@
#ifndef CHROME_BROWSER_OPTIMIZATION_GUIDE_OPTIMIZATION_GUIDE_WEB_CONTENTS_OBSERVER_H_ #ifndef CHROME_BROWSER_OPTIMIZATION_GUIDE_OPTIMIZATION_GUIDE_WEB_CONTENTS_OBSERVER_H_
#define CHROME_BROWSER_OPTIMIZATION_GUIDE_OPTIMIZATION_GUIDE_WEB_CONTENTS_OBSERVER_H_ #define CHROME_BROWSER_OPTIMIZATION_GUIDE_OPTIMIZATION_GUIDE_WEB_CONTENTS_OBSERVER_H_
#include <map>
#include <string> #include <string>
#include <unordered_map>
#include <vector> #include <vector>
#include "base/macros.h" #include "base/macros.h"
...@@ -65,7 +65,7 @@ class OptimizationGuideWebContentsObserver ...@@ -65,7 +65,7 @@ class OptimizationGuideWebContentsObserver
bool has_committed); bool has_committed);
// The data related to a given navigation ID. // The data related to a given navigation ID.
std::unordered_map<int64_t, OptimizationGuideNavigationData> std::map<int64_t, OptimizationGuideNavigationData>
inflight_optimization_guide_navigation_datas_; inflight_optimization_guide_navigation_datas_;
// Initialized in constructor. It may be null if the // Initialized in constructor. It may be null if the
......
...@@ -7,9 +7,9 @@ ...@@ -7,9 +7,9 @@
#include <map> #include <map>
#include <string> #include <string>
#include <unordered_set>
#include "base/callback.h" #include "base/callback.h"
#include "base/containers/flat_set.h"
#include "base/macros.h" #include "base/macros.h"
#include "base/memory/scoped_refptr.h" #include "base/memory/scoped_refptr.h"
#include "base/memory/weak_ptr.h" #include "base/memory/weak_ptr.h"
...@@ -163,7 +163,7 @@ class HintCacheStore { ...@@ -163,7 +163,7 @@ class HintCacheStore {
friend class HintUpdateData; friend class HintUpdateData;
using EntryKeyPrefix = std::string; using EntryKeyPrefix = std::string;
using EntryKeySet = std::unordered_set<EntryKey>; using EntryKeySet = base::flat_set<EntryKey>;
using EntryVector = using EntryVector =
leveldb_proto::ProtoDatabase<proto::StoreEntry>::KeyEntryVector; leveldb_proto::ProtoDatabase<proto::StoreEntry>::KeyEntryVector;
......
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
#include <string> #include <string>
#include "base/containers/flat_set.h"
#include "base/metrics/field_trial_params.h" #include "base/metrics/field_trial_params.h"
#include "base/strings/stringprintf.h" #include "base/strings/stringprintf.h"
#include "components/optimization_guide/hint_update_data.h" #include "components/optimization_guide/hint_update_data.h"
...@@ -90,7 +91,7 @@ bool ProcessHints(google::protobuf::RepeatedPtrField<proto::Hint>* hints, ...@@ -90,7 +91,7 @@ bool ProcessHints(google::protobuf::RepeatedPtrField<proto::Hint>* hints,
if (!hint_update_data) if (!hint_update_data)
return false; return false;
std::unordered_set<std::string> seen_host_suffixes; base::flat_set<std::string> seen_host_suffixes;
bool did_process_hints = false; bool did_process_hints = false;
// Process each hint in the the hint configuration. The hints are mutable // Process each hint in the the hint configuration. The hints are mutable
......
...@@ -45,9 +45,9 @@ ConvertPreviewsTypeToOptimizationType(PreviewsType previews_type) { ...@@ -45,9 +45,9 @@ ConvertPreviewsTypeToOptimizationType(PreviewsType previews_type) {
// Returns the optimization types to register with the Optimization Guide // Returns the optimization types to register with the Optimization Guide
// Decider based on which Previews are enabled for the session. // Decider based on which Previews are enabled for the session.
std::unordered_set<optimization_guide::proto::OptimizationType> base::flat_set<optimization_guide::proto::OptimizationType>
GetOptimizationTypesToRegister() { GetOptimizationTypesToRegister() {
std::unordered_set<optimization_guide::proto::OptimizationType> base::flat_set<optimization_guide::proto::OptimizationType>
optimization_types; optimization_types;
if (params::IsNoScriptPreviewsEnabled()) if (params::IsNoScriptPreviewsEnabled())
......
...@@ -8,9 +8,9 @@ ...@@ -8,9 +8,9 @@
#include "components/previews/content/previews_optimization_guide.h" #include "components/previews/content/previews_optimization_guide.h"
#include <string> #include <string>
#include <unordered_set>
#include <vector> #include <vector>
#include "base/containers/flat_set.h"
#include "base/containers/mru_cache.h" #include "base/containers/mru_cache.h"
#include "components/optimization_guide/proto/hints.pb.h" #include "components/optimization_guide/proto/hints.pb.h"
...@@ -51,7 +51,7 @@ class PreviewsOptimizationGuideDecider : public PreviewsOptimizationGuide { ...@@ -51,7 +51,7 @@ class PreviewsOptimizationGuideDecider : public PreviewsOptimizationGuide {
base::MRUCache<GURL, std::vector<std::string>> resource_loading_hints_cache_; base::MRUCache<GURL, std::vector<std::string>> resource_loading_hints_cache_;
// The optimization types registered with |optimization_guide_decider_|. // The optimization types registered with |optimization_guide_decider_|.
const std::unordered_set<optimization_guide::proto::OptimizationType> const base::flat_set<optimization_guide::proto::OptimizationType>
registered_optimization_types_; registered_optimization_types_;
DISALLOW_COPY_AND_ASSIGN(PreviewsOptimizationGuideDecider); DISALLOW_COPY_AND_ASSIGN(PreviewsOptimizationGuideDecider);
......
...@@ -8,10 +8,10 @@ ...@@ -8,10 +8,10 @@
#include <memory> #include <memory>
#include <string> #include <string>
#include <tuple> #include <tuple>
#include <unordered_set>
#include <vector> #include <vector>
#include "base/command_line.h" #include "base/command_line.h"
#include "base/containers/flat_set.h"
#include "base/test/scoped_feature_list.h" #include "base/test/scoped_feature_list.h"
#include "components/optimization_guide/optimization_guide_decider.h" #include "components/optimization_guide/optimization_guide_decider.h"
#include "components/previews/content/previews_user_data.h" #include "components/previews/content/previews_user_data.h"
...@@ -33,13 +33,13 @@ class TestOptimizationGuideDecider ...@@ -33,13 +33,13 @@ class TestOptimizationGuideDecider
std::vector<optimization_guide::proto::OptimizationType> std::vector<optimization_guide::proto::OptimizationType>
optimization_types) override { optimization_types) override {
registered_optimization_types_ = registered_optimization_types_ =
std::unordered_set<optimization_guide::proto::OptimizationType>( base::flat_set<optimization_guide::proto::OptimizationType>(
optimization_types.begin(), optimization_types.end()); optimization_types.begin(), optimization_types.end());
} }
// Returns the optimization types registered with the Optimization Guide // Returns the optimization types registered with the Optimization Guide
// Decider. // Decider.
std::unordered_set<optimization_guide::proto::OptimizationType> base::flat_set<optimization_guide::proto::OptimizationType>
registered_optimization_types() { registered_optimization_types() {
return registered_optimization_types_; return registered_optimization_types_;
} }
...@@ -78,7 +78,7 @@ class TestOptimizationGuideDecider ...@@ -78,7 +78,7 @@ class TestOptimizationGuideDecider
private: private:
// The optimization types that were registered with the Optimization Guide // The optimization types that were registered with the Optimization Guide
// Decider. // Decider.
std::unordered_set<optimization_guide::proto::OptimizationType> base::flat_set<optimization_guide::proto::OptimizationType>
registered_optimization_types_; registered_optimization_types_;
std::map<std::tuple<GURL, optimization_guide::proto::OptimizationType>, std::map<std::tuple<GURL, optimization_guide::proto::OptimizationType>,
...@@ -169,7 +169,7 @@ TEST_F(PreviewsOptimizationGuideDeciderTest, ...@@ -169,7 +169,7 @@ TEST_F(PreviewsOptimizationGuideDeciderTest,
PreviewsOptimizationGuideDecider decider(optimization_guide_decider()); PreviewsOptimizationGuideDecider decider(optimization_guide_decider());
std::unordered_set<optimization_guide::proto::OptimizationType> base::flat_set<optimization_guide::proto::OptimizationType>
registered_optimization_types = registered_optimization_types =
optimization_guide_decider()->registered_optimization_types(); optimization_guide_decider()->registered_optimization_types();
EXPECT_EQ(4u, registered_optimization_types.size()); EXPECT_EQ(4u, registered_optimization_types.size());
...@@ -200,7 +200,7 @@ TEST_F(PreviewsOptimizationGuideDeciderTest, ...@@ -200,7 +200,7 @@ TEST_F(PreviewsOptimizationGuideDeciderTest,
PreviewsOptimizationGuideDecider decider(optimization_guide_decider()); PreviewsOptimizationGuideDecider decider(optimization_guide_decider());
std::unordered_set<optimization_guide::proto::OptimizationType> base::flat_set<optimization_guide::proto::OptimizationType>
registered_optimization_types = registered_optimization_types =
optimization_guide_decider()->registered_optimization_types(); optimization_guide_decider()->registered_optimization_types();
EXPECT_EQ(1u, registered_optimization_types.size()); EXPECT_EQ(1u, registered_optimization_types.size());
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment