-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[lldb] Use heterogenous lookups with std::map (NFC) (#115590) #115634
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
kazutakahirata
merged 2 commits into
llvm:main
from
kazutakahirata:cleanup_001_heterogenous_lldb
Nov 10, 2024
Merged
[lldb] Use heterogenous lookups with std::map (NFC) (#115590) #115634
kazutakahirata
merged 2 commits into
llvm:main
from
kazutakahirata:cleanup_001_heterogenous_lldb
Nov 10, 2024
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Heterogenous lookups allow us to call find with StringRef, avoiding a temporary heap allocation of std::string.
@llvm/pr-subscribers-lldb Author: Kazu Hirata (kazutakahirata) ChangesHeterogenous lookups allow us to call find with StringRef, avoiding a Full diff: https://github.com/llvm/llvm-project/pull/115634.diff 2 Files Affected:
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;
}
|
nikic
approved these changes
Nov 10, 2024
kazutakahirata
added a commit
to kazutakahirata/llvm-project
that referenced
this pull request
Nov 11, 2024
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).
kazutakahirata
added a commit
that referenced
this pull request
Nov 11, 2024
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 (#115634).
Groverkss
pushed a commit
to iree-org/llvm-project
that referenced
this pull request
Nov 15, 2024
…vm#115634) Heterogenous lookups allow us to call find with StringRef, avoiding a temporary heap allocation of std::string.
Groverkss
pushed a commit
to iree-org/llvm-project
that referenced
this pull request
Nov 15, 2024
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).
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Heterogenous lookups allow us to call find with StringRef, avoiding a
temporary heap allocation of std::string.