Pass OptionTypeInfo maps by const& (#5295)
Summary: In options_helper.cc various functions take a const unordered_map of string -> TypeInfo for options handling. These functions pass by-value the (const) maps, resulting in unnecessary copies. Change to pass by reference. This results in a noticable reduction in the amount of time spent parsing options - in my case a set of unit tests using RocksDB which call SetOptions() to modify options see a ~25% runtime reduction. Pull Request resolved: https://github.com/facebook/rocksdb/pull/5295 Differential Revision: D15296334 Pulled By: riversand963 fbshipit-source-id: 4d4be3db635264943607911b296dda27fd7ce1a7
This commit is contained in:
parent
468ca61105
commit
8149bb9d6a
@ -255,7 +255,7 @@ const std::string kNameMergeOperator = "merge_operator";
|
|||||||
template <typename T>
|
template <typename T>
|
||||||
Status GetStringFromStruct(
|
Status GetStringFromStruct(
|
||||||
std::string* opt_string, const T& options,
|
std::string* opt_string, const T& options,
|
||||||
const std::unordered_map<std::string, OptionTypeInfo> type_info,
|
const std::unordered_map<std::string, OptionTypeInfo>& type_info,
|
||||||
const std::string& delimiter);
|
const std::string& delimiter);
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
@ -350,7 +350,7 @@ bool FIFOCompactionOptionsSpecialCase(const std::string& opt_str,
|
|||||||
template <typename T>
|
template <typename T>
|
||||||
bool SerializeStruct(
|
bool SerializeStruct(
|
||||||
const T& options, std::string* value,
|
const T& options, std::string* value,
|
||||||
std::unordered_map<std::string, OptionTypeInfo> type_info_map) {
|
const std::unordered_map<std::string, OptionTypeInfo>& type_info_map) {
|
||||||
std::string opt_str;
|
std::string opt_str;
|
||||||
Status s = GetStringFromStruct(&opt_str, options, type_info_map, ";");
|
Status s = GetStringFromStruct(&opt_str, options, type_info_map, ";");
|
||||||
if (!s.ok()) {
|
if (!s.ok()) {
|
||||||
@ -363,7 +363,7 @@ bool SerializeStruct(
|
|||||||
template <typename T>
|
template <typename T>
|
||||||
bool ParseSingleStructOption(
|
bool ParseSingleStructOption(
|
||||||
const std::string& opt_val_str, T* options,
|
const std::string& opt_val_str, T* options,
|
||||||
std::unordered_map<std::string, OptionTypeInfo> type_info_map) {
|
const std::unordered_map<std::string, OptionTypeInfo>& type_info_map) {
|
||||||
size_t end = opt_val_str.find('=');
|
size_t end = opt_val_str.find('=');
|
||||||
std::string key = opt_val_str.substr(0, end);
|
std::string key = opt_val_str.substr(0, end);
|
||||||
std::string value = opt_val_str.substr(end + 1);
|
std::string value = opt_val_str.substr(end + 1);
|
||||||
@ -380,7 +380,7 @@ bool ParseSingleStructOption(
|
|||||||
template <typename T>
|
template <typename T>
|
||||||
bool ParseStructOptions(
|
bool ParseStructOptions(
|
||||||
const std::string& opt_str, T* options,
|
const std::string& opt_str, T* options,
|
||||||
std::unordered_map<std::string, OptionTypeInfo> type_info_map) {
|
const std::unordered_map<std::string, OptionTypeInfo>& type_info_map) {
|
||||||
assert(!opt_str.empty());
|
assert(!opt_str.empty());
|
||||||
|
|
||||||
size_t start = 0;
|
size_t start = 0;
|
||||||
@ -1092,7 +1092,7 @@ Status ParseColumnFamilyOption(const std::string& name,
|
|||||||
template <typename T>
|
template <typename T>
|
||||||
bool SerializeSingleStructOption(
|
bool SerializeSingleStructOption(
|
||||||
std::string* opt_string, const T& options,
|
std::string* opt_string, const T& options,
|
||||||
const std::unordered_map<std::string, OptionTypeInfo> type_info,
|
const std::unordered_map<std::string, OptionTypeInfo>& type_info,
|
||||||
const std::string& name, const std::string& delimiter) {
|
const std::string& name, const std::string& delimiter) {
|
||||||
auto iter = type_info.find(name);
|
auto iter = type_info.find(name);
|
||||||
if (iter == type_info.end()) {
|
if (iter == type_info.end()) {
|
||||||
@ -1112,7 +1112,7 @@ bool SerializeSingleStructOption(
|
|||||||
template <typename T>
|
template <typename T>
|
||||||
Status GetStringFromStruct(
|
Status GetStringFromStruct(
|
||||||
std::string* opt_string, const T& options,
|
std::string* opt_string, const T& options,
|
||||||
const std::unordered_map<std::string, OptionTypeInfo> type_info,
|
const std::unordered_map<std::string, OptionTypeInfo>& type_info,
|
||||||
const std::string& delimiter) {
|
const std::string& delimiter) {
|
||||||
assert(opt_string);
|
assert(opt_string);
|
||||||
opt_string->clear();
|
opt_string->clear();
|
||||||
|
Loading…
Reference in New Issue
Block a user