Skip to content

Commit 15ce2e1

Browse files
[lldb] Use heterogenous lookups with std::map (NFC) (#115590) (#115634)
Heterogenous lookups allow us to call find with StringRef, avoiding a temporary heap allocation of std::string.
1 parent 1e25c92 commit 15ce2e1

File tree

2 files changed

+8
-6
lines changed

2 files changed

+8
-6
lines changed

lldb/include/lldb/Interpreter/CommandObject.h

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,9 @@ namespace lldb_private {
3535

3636
template <typename ValueType>
3737
int AddNamesMatchingPartialString(
38-
const std::map<std::string, ValueType> &in_map, llvm::StringRef cmd_str,
39-
StringList &matches, StringList *descriptions = nullptr) {
38+
const std::map<std::string, ValueType, std::less<>> &in_map,
39+
llvm::StringRef cmd_str, StringList &matches,
40+
StringList *descriptions = nullptr) {
4041
int number_added = 0;
4142

4243
const bool add_all = cmd_str.empty();
@@ -54,7 +55,8 @@ int AddNamesMatchingPartialString(
5455
}
5556

5657
template <typename ValueType>
57-
size_t FindLongestCommandWord(std::map<std::string, ValueType> &dict) {
58+
size_t
59+
FindLongestCommandWord(std::map<std::string, ValueType, std::less<>> &dict) {
5860
auto end = dict.end();
5961
size_t max_len = 0;
6062

@@ -107,7 +109,7 @@ class CommandObject : public std::enable_shared_from_this<CommandObject> {
107109
typedef std::vector<CommandArgumentData>
108110
CommandArgumentEntry; // Used to build individual command argument lists
109111

110-
typedef std::map<std::string, lldb::CommandObjectSP> CommandMap;
112+
typedef std::map<std::string, lldb::CommandObjectSP, std::less<>> CommandMap;
111113

112114
CommandObject(CommandInterpreter &interpreter, llvm::StringRef name,
113115
llvm::StringRef help = "", llvm::StringRef syntax = "",

lldb/source/Commands/CommandObjectMultiword.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ CommandObjectMultiword::GetSubcommandSPExact(llvm::StringRef sub_cmd) {
3232
if (m_subcommand_dict.empty())
3333
return {};
3434

35-
auto pos = m_subcommand_dict.find(std::string(sub_cmd));
35+
auto pos = m_subcommand_dict.find(sub_cmd);
3636
if (pos == m_subcommand_dict.end())
3737
return {};
3838

@@ -64,7 +64,7 @@ CommandObjectSP CommandObjectMultiword::GetSubcommandSP(llvm::StringRef sub_cmd,
6464
// function, since I now know I have an exact match...
6565

6666
sub_cmd = matches->GetStringAtIndex(0);
67-
pos = m_subcommand_dict.find(std::string(sub_cmd));
67+
pos = m_subcommand_dict.find(sub_cmd);
6868
if (pos != m_subcommand_dict.end())
6969
return_cmd_sp = pos->second;
7070
}

0 commit comments

Comments
 (0)