[Lldb-commits] [lldb] dd17cf4 - [lldb] Minor improvements to AddNamesMatchingPartialString (NFC) (#136760)
via lldb-commits
lldb-commits at lists.llvm.org
Wed Apr 23 15:21:38 PDT 2025
Author: Dave Lee
Date: 2025-04-23T15:21:34-07:00
New Revision: dd17cf4480fc55c38813769a46fb2807397d8f72
URL: https://github.com/llvm/llvm-project/commit/dd17cf4480fc55c38813769a46fb2807397d8f72
DIFF: https://github.com/llvm/llvm-project/commit/dd17cf4480fc55c38813769a46fb2807397d8f72.diff
LOG: [lldb] Minor improvements to AddNamesMatchingPartialString (NFC) (#136760)
The primary changes are:
1. Avoid allocating a temporary `std::string` each time in the loop
2. Use `starts_with` instead of `find(...) == 0`
Added:
Modified:
lldb/include/lldb/Interpreter/CommandObject.h
Removed:
################################################################################
diff --git a/lldb/include/lldb/Interpreter/CommandObject.h b/lldb/include/lldb/Interpreter/CommandObject.h
index e6fea9e022c43..8e33edbc4c794 100644
--- a/lldb/include/lldb/Interpreter/CommandObject.h
+++ b/lldb/include/lldb/Interpreter/CommandObject.h
@@ -40,14 +40,13 @@ int AddNamesMatchingPartialString(
StringList *descriptions = nullptr) {
int number_added = 0;
- const bool add_all = cmd_str.empty();
-
- for (auto iter = in_map.begin(), end = in_map.end(); iter != end; iter++) {
- if (add_all || (iter->first.find(std::string(cmd_str), 0) == 0)) {
+ for (const auto &[name, cmd] : in_map) {
+ llvm::StringRef cmd_name = name;
+ if (cmd_name.starts_with(cmd_str)) {
++number_added;
- matches.AppendString(iter->first.c_str());
+ matches.AppendString(name);
if (descriptions)
- descriptions->AppendString(iter->second->GetHelp());
+ descriptions->AppendString(cmd->GetHelp());
}
}
More information about the lldb-commits
mailing list