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

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


https://github.com/bulbazord created https://github.com/llvm/llvm-project/pull/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.

>From ff81bed6c8c1711ae0b5abe99ab2143751846a90 Mon Sep 17 00:00:00 2001
From: Alex Langford <alangford at apple.com>
Date: Fri, 5 Jan 2024 16:57:04 -0800
Subject: [PATCH] [lldb][NFCI] Change return type of
 BreakpointIDList::GetBreakpointIDAtIndex

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 to prevent lifetime issues.
---
 lldb/include/lldb/Breakpoint/BreakpointIDList.h | 3 +--
 lldb/source/Breakpoint/BreakpointIDList.cpp     | 8 +++-----
 2 files changed, 4 insertions(+), 7 deletions(-)

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) {



More information about the lldb-commits mailing list