Skip to content

Commit 1e92ad4

Browse files
authored
[lldb] Use const reference for range variables to improve performance (NFC) (#94840)
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 #91213 Fix #91217 Fix #91219 Fix #91220
1 parent 80d00bf commit 1e92ad4

File tree

4 files changed

+4
-4
lines changed

4 files changed

+4
-4
lines changed

lldb/source/API/SBBreakpoint.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -714,7 +714,7 @@ void SBBreakpoint::GetNames(SBStringList &names) {
714714
bkpt_sp->GetTarget().GetAPIMutex());
715715
std::vector<std::string> names_vec;
716716
bkpt_sp->GetNames(names_vec);
717-
for (std::string name : names_vec) {
717+
for (const std::string &name : names_vec) {
718718
names.AppendString(name.c_str());
719719
}
720720
}

lldb/source/API/SBTarget.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1147,7 +1147,7 @@ void SBTarget::GetBreakpointNames(SBStringList &names) {
11471147

11481148
std::vector<std::string> name_vec;
11491149
target_sp->GetBreakpointNames(name_vec);
1150-
for (auto name : name_vec)
1150+
for (const auto &name : name_vec)
11511151
names.AppendString(name.c_str());
11521152
}
11531153
}

lldb/source/Breakpoint/Breakpoint.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -885,7 +885,7 @@ void Breakpoint::GetDescription(Stream *s, lldb::DescriptionLevel level,
885885
s->Printf("Names:");
886886
s->EOL();
887887
s->IndentMore();
888-
for (std::string name : m_name_list) {
888+
for (const std::string &name : m_name_list) {
889889
s->Indent();
890890
s->Printf("%s\n", name.c_str());
891891
}

lldb/source/Breakpoint/BreakpointIDList.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,7 @@ llvm::Error BreakpointIDList::FindAndReplaceIDRanges(
259259

260260
if (!names_found.empty()) {
261261
for (BreakpointSP bkpt_sp : target->GetBreakpointList().Breakpoints()) {
262-
for (std::string name : names_found) {
262+
for (const std::string &name : names_found) {
263263
if (bkpt_sp->MatchesName(name.c_str())) {
264264
StreamString canonical_id_str;
265265
BreakpointID::GetCanonicalReference(

0 commit comments

Comments
 (0)