Skip to content

Commit dd17cf4

Browse files
authored
[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`
1 parent cd826d6 commit dd17cf4

File tree

1 file changed

+5
-6
lines changed

1 file changed

+5
-6
lines changed

lldb/include/lldb/Interpreter/CommandObject.h

+5-6
Original file line numberDiff line numberDiff line change
@@ -40,14 +40,13 @@ int AddNamesMatchingPartialString(
4040
StringList *descriptions = nullptr) {
4141
int number_added = 0;
4242

43-
const bool add_all = cmd_str.empty();
44-
45-
for (auto iter = in_map.begin(), end = in_map.end(); iter != end; iter++) {
46-
if (add_all || (iter->first.find(std::string(cmd_str), 0) == 0)) {
43+
for (const auto &[name, cmd] : in_map) {
44+
llvm::StringRef cmd_name = name;
45+
if (cmd_name.starts_with(cmd_str)) {
4746
++number_added;
48-
matches.AppendString(iter->first.c_str());
47+
matches.AppendString(name);
4948
if (descriptions)
50-
descriptions->AppendString(iter->second->GetHelp());
49+
descriptions->AppendString(cmd->GetHelp());
5150
}
5251
}
5352

0 commit comments

Comments
 (0)