Skip to content

Commit

Permalink
[lldb] Use const reference for range variables to improve performance…
Browse files Browse the repository at this point in the history
… (NFC)

Cppcheck recommends using a const reference for range variables in a for-each loop.
This avoids unnecessary copying of elements, improving performance.

Caught by cppcheck -
lldb/source/API/SBBreakpoint.cpp:717:22: performance: Range variable 'name' should be declared as const reference. [iterateByValue]
lldb/source/API/SBTarget.cpp:1150:15: performance: Range variable 'name' should be declared as const reference. [iterateByValue]
lldb/source/Breakpoint/Breakpoint.cpp:888:26: performance: Range variable 'name' should be declared as const reference. [iterateByValue]

Fix #91213
Fix #91217
Fix #91219
  • Loading branch information
xgupta committed Jun 8, 2024
1 parent ac40463 commit 25fb87d
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 3 deletions.
2 changes: 1 addition & 1 deletion lldb/source/API/SBBreakpoint.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -714,7 +714,7 @@ void SBBreakpoint::GetNames(SBStringList &names) {
bkpt_sp->GetTarget().GetAPIMutex());
std::vector<std::string> names_vec;
bkpt_sp->GetNames(names_vec);
for (std::string name : names_vec) {
for (const std::string &name : names_vec) {
names.AppendString(name.c_str());
}
}
Expand Down
2 changes: 1 addition & 1 deletion lldb/source/API/SBTarget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1147,7 +1147,7 @@ void SBTarget::GetBreakpointNames(SBStringList &names) {

std::vector<std::string> name_vec;
target_sp->GetBreakpointNames(name_vec);
for (auto name : name_vec)
for (const auto &name : name_vec)
names.AppendString(name.c_str());
}
}
Expand Down
2 changes: 1 addition & 1 deletion lldb/source/Breakpoint/Breakpoint.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -885,7 +885,7 @@ void Breakpoint::GetDescription(Stream *s, lldb::DescriptionLevel level,
s->Printf("Names:");
s->EOL();
s->IndentMore();
for (std::string name : m_name_list) {
for (const std::string &name : m_name_list) {
s->Indent();
s->Printf("%s\n", name.c_str());
}
Expand Down

0 comments on commit 25fb87d

Please sign in to comment.