1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 05:07:45 +00:00

Kernel: Always inline some KResult / KResultOr<> methods

Namely, those that contain assertions that can be easily eliminated at call site.
This commit is contained in:
Sergey Bugaev 2020-06-02 19:30:14 +03:00 committed by Andreas Kling
parent 1b4e88fb59
commit 1e266aec27

View file

@ -37,7 +37,7 @@ enum KSuccessTag {
class KResult { class KResult {
public: public:
explicit KResult(int negative_e) ALWAYS_INLINE explicit KResult(int negative_e)
: m_error(negative_e) : m_error(negative_e)
{ {
ASSERT(negative_e <= 0); ASSERT(negative_e <= 0);
@ -55,7 +55,7 @@ public:
private: private:
template<typename T> template<typename T>
friend class KResultOr; friend class KResultOr;
KResult() {} KResult() { }
int m_error { 0 }; int m_error { 0 };
}; };
@ -116,24 +116,24 @@ public:
} }
bool is_error() const { return m_is_error; } bool is_error() const { return m_is_error; }
KResult error() const ALWAYS_INLINE KResult error() const
{ {
ASSERT(m_is_error); ASSERT(m_is_error);
return m_error; return m_error;
} }
KResult result() const { return m_is_error ? KSuccess : m_error; } KResult result() const { return m_is_error ? KSuccess : m_error; }
T& value() ALWAYS_INLINE T& value()
{ {
ASSERT(!m_is_error); ASSERT(!m_is_error);
return *reinterpret_cast<T*>(&m_storage); return *reinterpret_cast<T*>(&m_storage);
} }
const T& value() const ALWAYS_INLINE const T& value() const
{ {
ASSERT(!m_is_error); ASSERT(!m_is_error);
return *reinterpret_cast<T*>(&m_storage); return *reinterpret_cast<T*>(&m_storage);
} }
T release_value() ALWAYS_INLINE T release_value()
{ {
ASSERT(!m_is_error); ASSERT(!m_is_error);
T released_value = *reinterpret_cast<T*>(&m_storage); T released_value = *reinterpret_cast<T*>(&m_storage);