Commit 70ebd037 authored by Collin Baker's avatar Collin Baker Committed by Commit Bot

Avoid memory allocation on base::Feature lookup

FeatureList::IsFeatureEnabled and FeatureList::GetAssociatedFieldTrial
call std::map<std::string, _>::find() with a const char* argument. By
default, this results in a conversion to an std::string, hence
incurring a memory allocation.

C++14 adds a new std::map::find() override to support map lookups by
types other than the key when a transparent comparator is specified.
This allows, for example, performing lookups in an
std::map<std::string, _> using a const char*. This CL changes the
declartion of FeatureList::overrides_ to support these allocation-free
lookups.

Bug: 960618

Change-Id: I59c8d2c16e86a3a6ca458b4047c445b1373df05d
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1600083
Commit-Queue: Collin Baker <collinbaker@chromium.org>
Reviewed-by: default avatarAlbert J. Wong <ajwong@chromium.org>
Cr-Commit-Position: refs/heads/master@{#657544}
parent 4e87b880
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
#ifndef BASE_FEATURE_LIST_H_ #ifndef BASE_FEATURE_LIST_H_
#define BASE_FEATURE_LIST_H_ #define BASE_FEATURE_LIST_H_
#include <functional>
#include <map> #include <map>
#include <memory> #include <memory>
#include <string> #include <string>
...@@ -287,7 +288,7 @@ class BASE_EXPORT FeatureList { ...@@ -287,7 +288,7 @@ class BASE_EXPORT FeatureList {
// Map from feature name to an OverrideEntry struct for the feature, if it // Map from feature name to an OverrideEntry struct for the feature, if it
// exists. // exists.
std::map<std::string, OverrideEntry> overrides_; std::map<std::string, OverrideEntry, std::less<>> overrides_;
// Locked map that keeps track of seen features, to ensure a single feature is // 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 // 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