1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 16:47:36 +00:00

AK+Kernel: Help the compiler inline a bunch of trivial methods

If these methods get inlined, the compiler is able to statically eliminate most
of the assertions. Alas, it doesn't realize this, and believes inlining them to
be too expensive. So give it a strong hint that it's not the case.

This *decreases* the kernel binary size.
This commit is contained in:
Sergey Bugaev 2020-05-20 14:59:31 +03:00 committed by Andreas Kling
parent 36dcbce161
commit d2b500fbcb
6 changed files with 51 additions and 56 deletions

View file

@ -39,14 +39,14 @@ template<typename T>
class RefPtr;
template<typename T>
inline void ref_if_not_null(T* ptr)
ALWAYS_INLINE void ref_if_not_null(T* ptr)
{
if (ptr)
ptr->ref();
}
template<typename T>
inline void unref_if_not_null(T* ptr)
ALWAYS_INLINE void unref_if_not_null(T* ptr)
{
if (ptr)
ptr->unref();
@ -59,42 +59,42 @@ public:
enum AdoptTag { Adopt };
NonnullRefPtr(const T& object)
ALWAYS_INLINE NonnullRefPtr(const T& object)
: m_ptr(const_cast<T*>(&object))
{
m_ptr->ref();
}
template<typename U>
NonnullRefPtr(const U& object)
ALWAYS_INLINE NonnullRefPtr(const U& object)
: m_ptr(&const_cast<U&>(object))
{
m_ptr->ref();
}
NonnullRefPtr(AdoptTag, T& object)
ALWAYS_INLINE NonnullRefPtr(AdoptTag, T& object)
: m_ptr(&object)
{
}
NonnullRefPtr(NonnullRefPtr&& other)
ALWAYS_INLINE NonnullRefPtr(NonnullRefPtr&& other)
: m_ptr(&other.leak_ref())
{
}
template<typename U>
NonnullRefPtr(NonnullRefPtr<U>&& other)
ALWAYS_INLINE NonnullRefPtr(NonnullRefPtr<U>&& other)
: m_ptr(&other.leak_ref())
{
}
NonnullRefPtr(const NonnullRefPtr& other)
ALWAYS_INLINE NonnullRefPtr(const NonnullRefPtr& other)
: m_ptr(const_cast<T*>(other.ptr()))
{
m_ptr->ref();
}
template<typename U>
NonnullRefPtr(const NonnullRefPtr<U>& other)
ALWAYS_INLINE NonnullRefPtr(const NonnullRefPtr<U>& other)
: m_ptr(const_cast<U*>(other.ptr()))
{
m_ptr->ref();
}
~NonnullRefPtr()
ALWAYS_INLINE ~NonnullRefPtr()
{
unref_if_not_null(m_ptr);
m_ptr = nullptr;
@ -133,7 +133,7 @@ public:
return *this;
}
NonnullRefPtr& operator=(NonnullRefPtr&& other)
ALWAYS_INLINE NonnullRefPtr& operator=(NonnullRefPtr&& other)
{
NonnullRefPtr ptr(move(other));
swap(ptr);
@ -155,62 +155,62 @@ public:
return *this;
}
[[nodiscard]] T& leak_ref()
[[nodiscard]] ALWAYS_INLINE T& leak_ref()
{
ASSERT(m_ptr);
return *exchange(m_ptr, nullptr);
}
T* ptr()
ALWAYS_INLINE T* ptr()
{
ASSERT(m_ptr);
return m_ptr;
}
const T* ptr() const
ALWAYS_INLINE const T* ptr() const
{
ASSERT(m_ptr);
return m_ptr;
}
T* operator->()
ALWAYS_INLINE T* operator->()
{
ASSERT(m_ptr);
return m_ptr;
}
const T* operator->() const
ALWAYS_INLINE const T* operator->() const
{
ASSERT(m_ptr);
return m_ptr;
}
T& operator*()
ALWAYS_INLINE T& operator*()
{
ASSERT(m_ptr);
return *m_ptr;
}
const T& operator*() const
ALWAYS_INLINE const T& operator*() const
{
ASSERT(m_ptr);
return *m_ptr;
}
operator T*()
ALWAYS_INLINE operator T*()
{
ASSERT(m_ptr);
return m_ptr;
}
operator const T*() const
ALWAYS_INLINE operator const T*() const
{
ASSERT(m_ptr);
return m_ptr;
}
operator T&()
ALWAYS_INLINE operator T&()
{
ASSERT(m_ptr);
return *m_ptr;
}
operator const T&() const
ALWAYS_INLINE operator const T&() const
{
ASSERT(m_ptr);
return *m_ptr;