mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 12:07:45 +00:00
AK: Simplify RefPtr and NonnullRefPtr's leak_ref() functions
Use AK::exchange() to switch out the internal storage. Also mark these functions with [[nodiscard]] to provoke an compile-time error if they are called without using the return value.
This commit is contained in:
parent
15866714da
commit
fe25426ee4
2 changed files with 4 additions and 8 deletions
|
@ -148,14 +148,12 @@ public:
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
CALLABLE_WHEN(unconsumed)
|
[[nodiscard]] CALLABLE_WHEN(unconsumed)
|
||||||
SET_TYPESTATE(consumed)
|
SET_TYPESTATE(consumed)
|
||||||
T& leak_ref()
|
T& leak_ref()
|
||||||
{
|
{
|
||||||
ASSERT(m_ptr);
|
ASSERT(m_ptr);
|
||||||
T* leakedPtr = m_ptr;
|
return *exchange(m_ptr, nullptr);
|
||||||
m_ptr = nullptr;
|
|
||||||
return *leakedPtr;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
CALLABLE_WHEN("unconsumed","unknown")
|
CALLABLE_WHEN("unconsumed","unknown")
|
||||||
|
|
|
@ -188,11 +188,9 @@ public:
|
||||||
|
|
||||||
bool operator!() const { return !m_ptr; }
|
bool operator!() const { return !m_ptr; }
|
||||||
|
|
||||||
T* leak_ref()
|
[[nodiscard]] T* leak_ref()
|
||||||
{
|
{
|
||||||
T* leakedPtr = m_ptr;
|
return exchange(m_ptr, nullptr);
|
||||||
m_ptr = nullptr;
|
|
||||||
return leakedPtr;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
T* ptr() { return m_ptr; }
|
T* ptr() { return m_ptr; }
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue