@@ -988,26 +988,28 @@ std::string_view SchemaLoader::getSafeCppName(std::string_view type) noexcept
988988 std::regex::optimize | std::regex::ECMAScript);
989989
990990 // Cache the substitutions so we don't need to repeat a replacement.
991- static std::unordered_map<std::string, std::unique_ptr<std::string>> safeNames;
992- auto itr = std::find_if (safeNames.begin (), safeNames.end (), [type](const auto & entry) noexcept {
993- return entry.first == type;
994- });
991+ using entry_allocation = std::pair<std::string, std::string>;
992+ static std::unordered_map<std::string_view, std::unique_ptr<entry_allocation>> safeNames;
993+ auto itr = safeNames.find (type);
995994
996995 if (safeNames.cend () == itr)
997996 {
998- std::string cppName { type };
997+ std::string typeName { type };
999998
1000- if (std::regex_search (cppName, leading_Capital ) || std::regex_search (cppName, multiple_ ))
999+ if (std::regex_search (typeName, multiple_ ) || std::regex_search (typeName, leading_Capital ))
10011000 {
1002- std::tie (itr, std::ignore) = safeNames.emplace (std::string { type },
1003- std::make_unique<std::string>(
1004- std::regex_replace (std::regex_replace (cppName, multiple_, R"re( _)re" ),
1005- leading_Capital,
1006- R"re( $1)re" )));
1001+ auto cppName = std::regex_replace (std::regex_replace (typeName, multiple_, R"re( _)re" ),
1002+ leading_Capital,
1003+ R"re( $1)re" );
1004+
1005+ auto entry = std::make_unique<entry_allocation>(
1006+ entry_allocation { std::move (typeName), std::move (cppName) });
1007+
1008+ std::tie (itr, std::ignore) = safeNames.emplace (entry->first , std::move (entry));
10071009 }
10081010 }
10091011
1010- return (safeNames.cend () == itr) ? type : *( itr->second ) ;
1012+ return (safeNames.cend () == itr) ? type : itr->second -> second ;
10111013}
10121014
10131015OutputFieldList SchemaLoader::getOutputFields (const peg::ast_node::children_t & fields)
0 commit comments