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

via lldb-commits lldb-commits at lists.llvm.org
Mon Jan 8 10:52:04 PST 2024


Author: Alex Langford
Date: 2024-01-08T10:52:00-08:00
New Revision: 5cbf74b012c10e9cc841a27cd5d7335e556f47dd

URL: https://github.com/llvm/llvm-project/commit/5cbf74b012c10e9cc841a27cd5d7335e556f47dd
DIFF: https://github.com/llvm/llvm-project/commit/5cbf74b012c10e9cc841a27cd5d7335e556f47dd.diff

LOG: [lldb][NFCI] Change return type of BreakpointIDList::GetBreakpointIDAtIndex (#77166)

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.

Added: 
    

Modified: 
    lldb/include/lldb/Breakpoint/BreakpointIDList.h
    lldb/source/Breakpoint/BreakpointIDList.cpp

Removed: 
    


################################################################################
diff  --git a/lldb/include/lldb/Breakpoint/BreakpointIDList.h b/lldb/include/lldb/Breakpoint/BreakpointIDList.h
index 161d1a2d314ead..6910024695d898 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);
 
@@ -63,7 +63,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 c4fdbc370b223d..05c461827cadd8 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) {


        


More information about the lldb-commits mailing list