[Lldb-commits] [lldb] [lldb] Use heterogenous lookups with std::map (NFC) (#115590) (PR #115634)
Kazu Hirata via lldb-commits
lldb-commits at lists.llvm.org
Sun Nov 10 07:29:30 PST 2024
https://github.com/kazutakahirata updated https://github.com/llvm/llvm-project/pull/115634
>From 798021f7ff3a0f9578e7df39cc9bd6d11cb8c400 Mon Sep 17 00:00:00 2001
From: Kazu Hirata <kazu at google.com>
Date: Sat, 9 Nov 2024 14:48:11 -0800
Subject: [PATCH 1/2] [lldb] Use heterogenous lookups with std::map (NFC)
(#115590)
Heterogenous lookups allow us to call find with StringRef, avoiding a
temporary heap allocation of std::string.
---
lldb/include/lldb/Interpreter/CommandObject.h | 10 ++++++----
lldb/source/Commands/CommandObjectMultiword.cpp | 4 ++--
2 files changed, 8 insertions(+), 6 deletions(-)
diff --git a/lldb/include/lldb/Interpreter/CommandObject.h b/lldb/include/lldb/Interpreter/CommandObject.h
index c5167e5e0ecb6a..e6fea9e022c43a 100644
--- a/lldb/include/lldb/Interpreter/CommandObject.h
+++ b/lldb/include/lldb/Interpreter/CommandObject.h
@@ -35,8 +35,9 @@ namespace lldb_private {
template <typename ValueType>
int AddNamesMatchingPartialString(
- const std::map<std::string, ValueType> &in_map, llvm::StringRef cmd_str,
- StringList &matches, StringList *descriptions = nullptr) {
+ const std::map<std::string, ValueType, std::less<>> &in_map,
+ llvm::StringRef cmd_str, StringList &matches,
+ StringList *descriptions = nullptr) {
int number_added = 0;
const bool add_all = cmd_str.empty();
@@ -54,7 +55,8 @@ int AddNamesMatchingPartialString(
}
template <typename ValueType>
-size_t FindLongestCommandWord(std::map<std::string, ValueType> &dict) {
+size_t
+FindLongestCommandWord(std::map<std::string, ValueType, std::less<>> &dict) {
auto end = dict.end();
size_t max_len = 0;
@@ -107,7 +109,7 @@ class CommandObject : public std::enable_shared_from_this<CommandObject> {
typedef std::vector<CommandArgumentData>
CommandArgumentEntry; // Used to build individual command argument lists
- typedef std::map<std::string, lldb::CommandObjectSP> CommandMap;
+ typedef std::map<std::string, lldb::CommandObjectSP, std::less<>> CommandMap;
CommandObject(CommandInterpreter &interpreter, llvm::StringRef name,
llvm::StringRef help = "", llvm::StringRef syntax = "",
diff --git a/lldb/source/Commands/CommandObjectMultiword.cpp b/lldb/source/Commands/CommandObjectMultiword.cpp
index b4cdfea9b1a3ef..c99b75ff29144d 100644
--- a/lldb/source/Commands/CommandObjectMultiword.cpp
+++ b/lldb/source/Commands/CommandObjectMultiword.cpp
@@ -32,7 +32,7 @@ CommandObjectMultiword::GetSubcommandSPExact(llvm::StringRef sub_cmd) {
if (m_subcommand_dict.empty())
return {};
- auto pos = m_subcommand_dict.find(std::string(sub_cmd));
+ auto pos = m_subcommand_dict.find(sub_cmd);
if (pos == m_subcommand_dict.end())
return {};
@@ -64,7 +64,7 @@ CommandObjectSP CommandObjectMultiword::GetSubcommandSP(llvm::StringRef sub_cmd,
// function, since I now know I have an exact match...
sub_cmd = matches->GetStringAtIndex(0);
- pos = m_subcommand_dict.find(std::string(sub_cmd));
+ pos = m_subcommand_dict.find(sub_cmd);
if (pos != m_subcommand_dict.end())
return_cmd_sp = pos->second;
}
>From 7cce7231ee08e788fa9e528e92dc018fd0b653a2 Mon Sep 17 00:00:00 2001
From: Kazu Hirata <kazu at google.com>
Date: Sun, 10 Nov 2024 07:29:15 -0800
Subject: [PATCH 2/2] Trigger build
More information about the lldb-commits
mailing list