From 8149bb9d6ab8ef55a30e9906f0bca8e6e0a42bec Mon Sep 17 00:00:00 2001 From: Dave Rigby Date: Wed, 15 May 2019 14:19:04 -0700 Subject: [PATCH] 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 --- options/options_helper.cc | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/options/options_helper.cc b/options/options_helper.cc index c33c2be6f..dbee1636d 100644 --- a/options/options_helper.cc +++ b/options/options_helper.cc @@ -255,7 +255,7 @@ const std::string kNameMergeOperator = "merge_operator"; template Status GetStringFromStruct( std::string* opt_string, const T& options, - const std::unordered_map type_info, + const std::unordered_map& type_info, const std::string& delimiter); namespace { @@ -350,7 +350,7 @@ bool FIFOCompactionOptionsSpecialCase(const std::string& opt_str, template bool SerializeStruct( const T& options, std::string* value, - std::unordered_map type_info_map) { + const std::unordered_map& type_info_map) { std::string opt_str; Status s = GetStringFromStruct(&opt_str, options, type_info_map, ";"); if (!s.ok()) { @@ -363,7 +363,7 @@ bool SerializeStruct( template bool ParseSingleStructOption( const std::string& opt_val_str, T* options, - std::unordered_map type_info_map) { + const std::unordered_map& type_info_map) { size_t end = opt_val_str.find('='); std::string key = opt_val_str.substr(0, end); std::string value = opt_val_str.substr(end + 1); @@ -380,7 +380,7 @@ bool ParseSingleStructOption( template bool ParseStructOptions( const std::string& opt_str, T* options, - std::unordered_map type_info_map) { + const std::unordered_map& type_info_map) { assert(!opt_str.empty()); size_t start = 0; @@ -1092,7 +1092,7 @@ Status ParseColumnFamilyOption(const std::string& name, template bool SerializeSingleStructOption( std::string* opt_string, const T& options, - const std::unordered_map type_info, + const std::unordered_map& type_info, const std::string& name, const std::string& delimiter) { auto iter = type_info.find(name); if (iter == type_info.end()) { @@ -1112,7 +1112,7 @@ bool SerializeSingleStructOption( template Status GetStringFromStruct( std::string* opt_string, const T& options, - const std::unordered_map type_info, + const std::unordered_map& type_info, const std::string& delimiter) { assert(opt_string); opt_string->clear();