mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 10:37:45 +00:00
AK: Add RETURNS_NONNULL attribute and use it
This attribute tells compilers that the pointer returned by a function is never null, which lets it optimize away null checks in some places. This seems like a nice addition to `NonnullOwnPtr` and `NonnullRefPtr`. Using this attribute causes extra UBSan checks to be emitted. To offset its performance loss, some additional methods were marked ALWAYS_INLINE, which lets the compiler optimize duplicate checks
This commit is contained in:
parent
65b2d3add3
commit
23d66fe719
3 changed files with 29 additions and 15 deletions
|
@ -98,17 +98,26 @@ public:
|
|||
return exchange(m_ptr, nullptr);
|
||||
}
|
||||
|
||||
T* ptr() { return m_ptr; }
|
||||
const T* ptr() const { return m_ptr; }
|
||||
ALWAYS_INLINE RETURNS_NONNULL T* ptr()
|
||||
{
|
||||
VERIFY(m_ptr);
|
||||
return m_ptr;
|
||||
}
|
||||
|
||||
T* operator->() { return m_ptr; }
|
||||
const T* operator->() const { return m_ptr; }
|
||||
ALWAYS_INLINE RETURNS_NONNULL const T* ptr() const
|
||||
{
|
||||
VERIFY(m_ptr);
|
||||
return m_ptr;
|
||||
}
|
||||
|
||||
T& operator*() { return *m_ptr; }
|
||||
const T& operator*() const { return *m_ptr; }
|
||||
ALWAYS_INLINE RETURNS_NONNULL T* operator->() { return ptr(); }
|
||||
ALWAYS_INLINE RETURNS_NONNULL const T* operator->() const { return ptr(); }
|
||||
|
||||
operator const T*() const { return m_ptr; }
|
||||
operator T*() { return m_ptr; }
|
||||
ALWAYS_INLINE T& operator*() { return *ptr(); }
|
||||
ALWAYS_INLINE const T& operator*() const { return *ptr(); }
|
||||
|
||||
ALWAYS_INLINE RETURNS_NONNULL operator const T*() const { return ptr(); }
|
||||
ALWAYS_INLINE RETURNS_NONNULL operator T*() { return ptr(); }
|
||||
|
||||
operator bool() const = delete;
|
||||
bool operator!() const = delete;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue