Commit f3a945c5 authored by Jeremy Roman's avatar Jeremy Roman Committed by Commit Bot

Use base::flat_map in base::FeatureList.

It is mostly accessed for read, which means that the memory locality is
likely to be more useful than pointer stability or fast insertions.

At least one call site to base::FeatureList has indicated concern about
the access times, and base/containers/README.md recommends flat_map for
cases such as this.

Two fields in a private struct must be non-const for this to work, since
having const fields makes them not assignable and thus not usable in
a vector.

Change-Id: Iaed0d07e5dd765e592d57f6ff5b38b2b48040119
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2560060Reviewed-by: default avatarDaniel Cheng <dcheng@chromium.org>
Commit-Queue: Jeremy Roman <jbroman@chromium.org>
Cr-Commit-Position: refs/heads/master@{#831144}
parent 65c5ccea
......@@ -13,6 +13,7 @@
#include <vector>
#include "base/base_export.h"
#include "base/containers/flat_map.h"
#include "base/gtest_prod_util.h"
#include "base/metrics/field_trial_params.h"
#include "base/metrics/persistent_memory_allocator.h"
......@@ -285,7 +286,7 @@ class BASE_EXPORT FeatureList {
struct OverrideEntry {
// The overridden enable (on/off) state of the feature.
const OverrideState overridden_state;
OverrideState overridden_state;
// An optional associated field trial, which will be activated when the
// state of the feature is queried for the first time. Weak pointer to the
......@@ -296,7 +297,7 @@ class BASE_EXPORT FeatureList {
// If it's not, and |field_trial| is not null, it means it is simply an
// associated field trial for reporting purposes (and |overridden_state|
// came from the command-line).
const bool overridden_by_field_trial;
bool overridden_by_field_trial;
// TODO(asvitkine): Expand this as more support is added.
......@@ -356,7 +357,7 @@ class BASE_EXPORT FeatureList {
// Map from feature name to an OverrideEntry struct for the feature, if it
// exists.
std::map<std::string, OverrideEntry, std::less<>> overrides_;
base::flat_map<std::string, OverrideEntry> overrides_;
// Locked map that keeps track of seen features, to ensure a single feature is
// only defined once. This verification is only done in builds with DCHECKs
......
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