mirror of
https://github.com/intel/llvm.git
synced 2026-01-24 17:01:00 +08:00
[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:
@@ -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());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user