aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorShivam Gupta <shivam98.tkg@gmail.com>2024-06-08 22:34:40 +0530
committerGitHub <noreply@github.com>2024-06-08 22:34:40 +0530
commit1e92ad41d8ef46fa3c628b05ba8ed481fedc17bd (patch)
tree97656b3545a74ce69ba3559b58b59a0a19dcc79a
parent80d00bf811cc3361c78e55243f8c5aa8deffdb0a (diff)
downloadllvm-1e92ad41d8ef46fa3c628b05ba8ed481fedc17bd.zip
llvm-1e92ad41d8ef46fa3c628b05ba8ed481fedc17bd.tar.gz
llvm-1e92ad41d8ef46fa3c628b05ba8ed481fedc17bd.tar.bz2
[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
-rw-r--r--lldb/source/API/SBBreakpoint.cpp2
-rw-r--r--lldb/source/API/SBTarget.cpp2
-rw-r--r--lldb/source/Breakpoint/Breakpoint.cpp2
-rw-r--r--lldb/source/Breakpoint/BreakpointIDList.cpp2
4 files changed, 4 insertions, 4 deletions
diff --git a/lldb/source/API/SBBreakpoint.cpp b/lldb/source/API/SBBreakpoint.cpp
index f1fb6f9..3d90804 100644
--- a/lldb/source/API/SBBreakpoint.cpp
+++ b/lldb/source/API/SBBreakpoint.cpp
@@ -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());
}
}
diff --git a/lldb/source/API/SBTarget.cpp b/lldb/source/API/SBTarget.cpp
index 962ce9b..adb9e64 100644
--- a/lldb/source/API/SBTarget.cpp
+++ b/lldb/source/API/SBTarget.cpp
@@ -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());
}
}
diff --git a/lldb/source/Breakpoint/Breakpoint.cpp b/lldb/source/Breakpoint/Breakpoint.cpp
index ae845e9..dc80d43 100644
--- a/lldb/source/Breakpoint/Breakpoint.cpp
+++ b/lldb/source/Breakpoint/Breakpoint.cpp
@@ -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());
}
diff --git a/lldb/source/Breakpoint/BreakpointIDList.cpp b/lldb/source/Breakpoint/BreakpointIDList.cpp
index 97af1d4..5fc9f95 100644
--- a/lldb/source/Breakpoint/BreakpointIDList.cpp
+++ b/lldb/source/Breakpoint/BreakpointIDList.cpp
@@ -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(