Skip to content

Commit ebcdc70

Browse files
[lldb] Use heterogenous lookups with std::map (NFC) (llvm#115684)
Heterogenous lookups allow us to call find with StringRef, avoiding a temporary heap allocation of std::string. Note that CommandMap just started accepting heterogeneous lookups (llvm#115634).
1 parent b9fb6b6 commit ebcdc70

File tree

1 file changed

+12
-15
lines changed

1 file changed

+12
-15
lines changed

lldb/source/Interpreter/CommandInterpreter.cpp

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1274,7 +1274,7 @@ CommandObject *CommandInterpreter::GetUserCommandObject(
12741274
llvm::StringRef cmd, StringList *matches, StringList *descriptions) const {
12751275
std::string cmd_str(cmd);
12761276
auto find_exact = [&](const CommandObject::CommandMap &map) {
1277-
auto found_elem = map.find(std::string(cmd));
1277+
auto found_elem = map.find(cmd);
12781278
if (found_elem == map.end())
12791279
return (CommandObject *)nullptr;
12801280
CommandObject *exact_cmd = found_elem->second.get();
@@ -1310,7 +1310,7 @@ CommandObject *CommandInterpreter::GetAliasCommandObject(
13101310
llvm::StringRef cmd, StringList *matches, StringList *descriptions) const {
13111311
auto find_exact =
13121312
[&](const CommandObject::CommandMap &map) -> CommandObject * {
1313-
auto found_elem = map.find(cmd.str());
1313+
auto found_elem = map.find(cmd);
13141314
if (found_elem == map.end())
13151315
return (CommandObject *)nullptr;
13161316
CommandObject *exact_cmd = found_elem->second.get();
@@ -1340,13 +1340,12 @@ CommandObject *CommandInterpreter::GetAliasCommandObject(
13401340
}
13411341

13421342
bool CommandInterpreter::CommandExists(llvm::StringRef cmd) const {
1343-
return m_command_dict.find(std::string(cmd)) != m_command_dict.end();
1343+
return m_command_dict.find(cmd) != m_command_dict.end();
13441344
}
13451345

13461346
bool CommandInterpreter::GetAliasFullName(llvm::StringRef cmd,
13471347
std::string &full_name) const {
1348-
bool exact_match =
1349-
(m_alias_dict.find(std::string(cmd)) != m_alias_dict.end());
1348+
bool exact_match = (m_alias_dict.find(cmd) != m_alias_dict.end());
13501349
if (exact_match) {
13511350
full_name.assign(std::string(cmd));
13521351
return exact_match;
@@ -1374,15 +1373,15 @@ bool CommandInterpreter::GetAliasFullName(llvm::StringRef cmd,
13741373
}
13751374

13761375
bool CommandInterpreter::AliasExists(llvm::StringRef cmd) const {
1377-
return m_alias_dict.find(std::string(cmd)) != m_alias_dict.end();
1376+
return m_alias_dict.find(cmd) != m_alias_dict.end();
13781377
}
13791378

13801379
bool CommandInterpreter::UserCommandExists(llvm::StringRef cmd) const {
1381-
return m_user_dict.find(std::string(cmd)) != m_user_dict.end();
1380+
return m_user_dict.find(cmd) != m_user_dict.end();
13821381
}
13831382

13841383
bool CommandInterpreter::UserMultiwordCommandExists(llvm::StringRef cmd) const {
1385-
return m_user_mw_dict.find(std::string(cmd)) != m_user_mw_dict.end();
1384+
return m_user_mw_dict.find(cmd) != m_user_mw_dict.end();
13861385
}
13871386

13881387
CommandAlias *
@@ -1406,7 +1405,7 @@ CommandInterpreter::AddAlias(llvm::StringRef alias_name,
14061405
}
14071406

14081407
bool CommandInterpreter::RemoveAlias(llvm::StringRef alias_name) {
1409-
auto pos = m_alias_dict.find(std::string(alias_name));
1408+
auto pos = m_alias_dict.find(alias_name);
14101409
if (pos != m_alias_dict.end()) {
14111410
m_alias_dict.erase(pos);
14121411
return true;
@@ -1415,7 +1414,7 @@ bool CommandInterpreter::RemoveAlias(llvm::StringRef alias_name) {
14151414
}
14161415

14171416
bool CommandInterpreter::RemoveCommand(llvm::StringRef cmd, bool force) {
1418-
auto pos = m_command_dict.find(std::string(cmd));
1417+
auto pos = m_command_dict.find(cmd);
14191418
if (pos != m_command_dict.end()) {
14201419
if (force || pos->second->IsRemovable()) {
14211420
// Only regular expression objects or python commands are removable under
@@ -1428,8 +1427,7 @@ bool CommandInterpreter::RemoveCommand(llvm::StringRef cmd, bool force) {
14281427
}
14291428

14301429
bool CommandInterpreter::RemoveUser(llvm::StringRef user_name) {
1431-
CommandObject::CommandMap::iterator pos =
1432-
m_user_dict.find(std::string(user_name));
1430+
CommandObject::CommandMap::iterator pos = m_user_dict.find(user_name);
14331431
if (pos != m_user_dict.end()) {
14341432
m_user_dict.erase(pos);
14351433
return true;
@@ -1438,8 +1436,7 @@ bool CommandInterpreter::RemoveUser(llvm::StringRef user_name) {
14381436
}
14391437

14401438
bool CommandInterpreter::RemoveUserMultiword(llvm::StringRef multi_name) {
1441-
CommandObject::CommandMap::iterator pos =
1442-
m_user_mw_dict.find(std::string(multi_name));
1439+
CommandObject::CommandMap::iterator pos = m_user_mw_dict.find(multi_name);
14431440
if (pos != m_user_mw_dict.end()) {
14441441
m_user_mw_dict.erase(pos);
14451442
return true;
@@ -2213,7 +2210,7 @@ const CommandAlias *
22132210
CommandInterpreter::GetAlias(llvm::StringRef alias_name) const {
22142211
OptionArgVectorSP ret_val;
22152212

2216-
auto pos = m_alias_dict.find(std::string(alias_name));
2213+
auto pos = m_alias_dict.find(alias_name);
22172214
if (pos != m_alias_dict.end())
22182215
return (CommandAlias *)pos->second.get();
22192216

0 commit comments

Comments
 (0)