1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-26 04:47:34 +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

@ -63,21 +63,21 @@ public:
: m_ptr(other.leak_ref())
{
}
RefPtr(const NonnullRefPtr<T>& other)
ALWAYS_INLINE RefPtr(const NonnullRefPtr<T>& other)
: m_ptr(const_cast<T*>(other.ptr()))
{
ASSERT(m_ptr);
m_ptr->ref();
}
template<typename U>
RefPtr(const NonnullRefPtr<U>& other)
ALWAYS_INLINE RefPtr(const NonnullRefPtr<U>& other)
: m_ptr(const_cast<U*>(other.ptr()))
{
ASSERT(m_ptr);
m_ptr->ref();
}
template<typename U>
RefPtr(NonnullRefPtr<U>&& other)
ALWAYS_INLINE RefPtr(NonnullRefPtr<U>&& other)
: m_ptr(&other.leak_ref())
{
ASSERT(m_ptr);
@ -98,7 +98,7 @@ public:
{
ref_if_not_null(m_ptr);
}
~RefPtr()
ALWAYS_INLINE ~RefPtr()
{
clear();
#ifdef SANITIZE_PTRS
@ -121,7 +121,7 @@ public:
::swap(m_ptr, other.m_ptr);
}
RefPtr& operator=(RefPtr&& other)
ALWAYS_INLINE RefPtr& operator=(RefPtr&& other)
{
RefPtr tmp = move(other);
swap(tmp);
@ -129,7 +129,7 @@ public:
}
template<typename U>
RefPtr& operator=(RefPtr<U>&& other)
ALWAYS_INLINE RefPtr& operator=(RefPtr<U>&& other)
{
RefPtr tmp = move(other);
swap(tmp);
@ -137,7 +137,7 @@ public:
}
template<typename U>
RefPtr& operator=(NonnullRefPtr<U>&& other)
ALWAYS_INLINE RefPtr& operator=(NonnullRefPtr<U>&& other)
{
RefPtr tmp = move(other);
swap(tmp);
@ -145,7 +145,7 @@ public:
return *this;
}
RefPtr& operator=(const NonnullRefPtr<T>& other)
ALWAYS_INLINE RefPtr& operator=(const NonnullRefPtr<T>& other)
{
RefPtr tmp = other;
swap(tmp);
@ -154,7 +154,7 @@ public:
}
template<typename U>
RefPtr& operator=(const NonnullRefPtr<U>& other)
ALWAYS_INLINE RefPtr& operator=(const NonnullRefPtr<U>& other)
{
RefPtr tmp = other;
swap(tmp);
@ -162,7 +162,7 @@ public:
return *this;
}
RefPtr& operator=(const RefPtr& other)
ALWAYS_INLINE RefPtr& operator=(const RefPtr& other)
{
RefPtr tmp = other;
swap(tmp);
@ -170,21 +170,21 @@ public:
}
template<typename U>
RefPtr& operator=(const RefPtr<U>& other)
ALWAYS_INLINE RefPtr& operator=(const RefPtr<U>& other)
{
RefPtr tmp = other;
swap(tmp);
return *this;
}
RefPtr& operator=(const T* ptr)
ALWAYS_INLINE RefPtr& operator=(const T* ptr)
{
RefPtr tmp = ptr;
swap(tmp);
return *this;
}
RefPtr& operator=(const T& object)
ALWAYS_INLINE RefPtr& operator=(const T& object)
{
RefPtr tmp = object;
swap(tmp);
@ -197,7 +197,7 @@ public:
return *this;
}
void clear()
ALWAYS_INLINE void clear()
{
unref_if_not_null(m_ptr);
m_ptr = nullptr;
@ -216,35 +216,35 @@ public:
return NonnullRefPtr<T>(NonnullRefPtr<T>::Adopt, *leak_ref());
}
T* ptr() { return m_ptr; }
const T* ptr() const { return m_ptr; }
ALWAYS_INLINE T* ptr() { return m_ptr; }
ALWAYS_INLINE const T* ptr() const { 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 const T*() const { return m_ptr; }
operator T*() { return m_ptr; }
ALWAYS_INLINE operator const T*() const { return m_ptr; }
ALWAYS_INLINE operator T*() { return m_ptr; }
operator bool() { return !!m_ptr; }