diff options
author | Alex Langford <alangford@apple.com> | 2024-01-08 10:52:00 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-01-08 10:52:00 -0800 |
commit | 5cbf74b012c10e9cc841a27cd5d7335e556f47dd (patch) | |
tree | 67be547abb406c2dd66da03abb8a20fcb9ece6d2 | |
parent | 07d6fbf8d80083470b4371f2ddabd656a9c317e6 (diff) | |
download | llvm-5cbf74b012c10e9cc841a27cd5d7335e556f47dd.zip llvm-5cbf74b012c10e9cc841a27cd5d7335e556f47dd.tar.gz llvm-5cbf74b012c10e9cc841a27cd5d7335e556f47dd.tar.bz2 |
[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.
-rw-r--r-- | lldb/include/lldb/Breakpoint/BreakpointIDList.h | 3 | ||||
-rw-r--r-- | 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 161d1a2..6910024 100644 --- a/lldb/include/lldb/Breakpoint/BreakpointIDList.h +++ b/lldb/include/lldb/Breakpoint/BreakpointIDList.h @@ -33,7 +33,7 @@ public: 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 @@ public: 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 c4fdbc3..05c4618 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) { |