[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`
This commit is contained in:
Dave Lee
2025-04-23 15:21:34 -07:00
committed by GitHub
parent cd826d6e84
commit dd17cf4480

View File

@@ -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());
}
}