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]
lldb/source/Breakpoint/BreakpointIDList.cpp:262:26: performance: Range variable 'name' should be declared as const reference. [iterateByValue]

Fix llvm#91213
Fix llvm#91217
Fix llvm#91219
Fix llvm#91220
  • Loading branch information
xgupta committed Jun 8, 2024
1 parent ac40463 commit ebfb9d8
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 4 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
2 changes: 1 addition & 1 deletion lldb/source/Breakpoint/BreakpointIDList.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ llvm::Error BreakpointIDList::FindAndReplaceIDRanges(

if (!names_found.empty()) {
for (BreakpointSP bkpt_sp : target->GetBreakpointList().Breakpoints()) {
for (std::string name : names_found) {
for (const std::string &name : names_found) {
if (bkpt_sp->MatchesName(name.c_str())) {
StreamString canonical_id_str;
BreakpointID::GetCanonicalReference(
Expand Down

0 comments on commit ebfb9d8

Please sign in to comment.