From 1d843c46eb6bfc62e99040c59ee870d4d47db0ba Mon Sep 17 00:00:00 2001 From: Tom Date: Sun, 7 Feb 2021 15:30:23 -0700 Subject: [PATCH] Kernel: KResultOr can use the same storage as the object for the error Since it can only hold either an object or an error code, we can share the same storage to hold either. --- Kernel/KResult.h | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/Kernel/KResult.h b/Kernel/KResult.h index b6988f13646..aaafe7d052f 100644 --- a/Kernel/KResult.h +++ b/Kernel/KResult.h @@ -172,8 +172,10 @@ public: } private: - alignas(T) char m_storage[sizeof(T)]; - KResult m_error; + union { + alignas(T) char m_storage[sizeof(T)]; + KResult m_error; + }; bool m_is_error { false }; bool m_have_storage { false }; };