[Lldb-commits] [lldb] [lldb] Use const reference for range variables to improve performance (NFC) (PR #94840)
via lldb-commits
lldb-commits at lists.llvm.org
Fri Jun 7 22:15:10 PDT 2024
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-lldb
Author: Shivam Gupta (xgupta)
<details>
<summary>Changes</summary>
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]
Fix #<!-- -->91213
---
Full diff: https://github.com/llvm/llvm-project/pull/94840.diff
1 Files Affected:
- (modified) lldb/source/API/SBBreakpoint.cpp (+1-1)
``````````diff
diff --git a/lldb/source/API/SBBreakpoint.cpp b/lldb/source/API/SBBreakpoint.cpp
index f1fb6f904f5f0..3d908047f9455 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());
}
}
``````````
</details>
https://github.com/llvm/llvm-project/pull/94840
More information about the lldb-commits
mailing list