[Lldb-commits] [lldb] [lldb][NFCI] Change return type of BreakpointIDList::GetBreakpointIDAtIndex (PR #77166)

via lldb-commits lldb-commits at lists.llvm.org
Fri Jan 5 17:09:42 PST 2024


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-lldb

Author: Alex Langford (bulbazord)

<details>
<summary>Changes</summary>

There are 2 motivations here:
1.) There is no need to hand out constant references to BreakpointIDs,
  they are only 8 bytes big. In addition, every use of this method already
  makes a copy anyway.
2.) Each BreakpointIDList held onto an invalid BreakpointID specifically to
  prevent lifetime issues. Returning a value means you can return an
  invalid BreakpointID instead of needing to allocate storage for an
  invalid BreakpointID.

---
Full diff: https://github.com/llvm/llvm-project/pull/77166.diff


2 Files Affected:

- (modified) lldb/include/lldb/Breakpoint/BreakpointIDList.h (+1-2) 
- (modified) lldb/source/Breakpoint/BreakpointIDList.cpp (+3-5) 


``````````diff
diff --git a/lldb/include/lldb/Breakpoint/BreakpointIDList.h b/lldb/include/lldb/Breakpoint/BreakpointIDList.h
index 924cb1f26b8b8a..bc58854ad4b708 100644
--- a/lldb/include/lldb/Breakpoint/BreakpointIDList.h
+++ b/lldb/include/lldb/Breakpoint/BreakpointIDList.h
@@ -33,7 +33,7 @@ class BreakpointIDList {
 
   size_t GetSize() const;
 
-  const BreakpointID &GetBreakpointIDAtIndex(size_t index) const;
+  BreakpointID GetBreakpointIDAtIndex(size_t index) const;
 
   bool RemoveBreakpointIDAtIndex(size_t index);
 
@@ -66,7 +66,6 @@ class BreakpointIDList {
 
 private:
   BreakpointIDArray m_breakpoint_ids;
-  BreakpointID m_invalid_id;
 
   BreakpointIDList(const BreakpointIDList &) = delete;
   const BreakpointIDList &operator=(const BreakpointIDList &) = delete;
diff --git a/lldb/source/Breakpoint/BreakpointIDList.cpp b/lldb/source/Breakpoint/BreakpointIDList.cpp
index dd16d3b6388c46..5a90650babaff9 100644
--- a/lldb/source/Breakpoint/BreakpointIDList.cpp
+++ b/lldb/source/Breakpoint/BreakpointIDList.cpp
@@ -20,17 +20,15 @@ using namespace lldb_private;
 
 // class BreakpointIDList
 
-BreakpointIDList::BreakpointIDList()
-    : m_invalid_id(LLDB_INVALID_BREAK_ID, LLDB_INVALID_BREAK_ID) {}
+BreakpointIDList::BreakpointIDList() : m_breakpoint_ids() {}
 
 BreakpointIDList::~BreakpointIDList() = default;
 
 size_t BreakpointIDList::GetSize() const { return m_breakpoint_ids.size(); }
 
-const BreakpointID &
-BreakpointIDList::GetBreakpointIDAtIndex(size_t index) const {
+BreakpointID BreakpointIDList::GetBreakpointIDAtIndex(size_t index) const {
   return ((index < m_breakpoint_ids.size()) ? m_breakpoint_ids[index]
-                                            : m_invalid_id);
+                                            : BreakpointID());
 }
 
 bool BreakpointIDList::RemoveBreakpointIDAtIndex(size_t index) {

``````````

</details>


https://github.com/llvm/llvm-project/pull/77166


More information about the lldb-commits mailing list