فهرست منبع

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.
Tom 4 سال پیش
والد
کامیت
1d843c46eb
1فایلهای تغییر یافته به همراه4 افزوده شده و 2 حذف شده
  1. 4 2
      Kernel/KResult.h

+ 4 - 2
Kernel/KResult.h

@@ -172,8 +172,10 @@ public:
     }
     }
 
 
 private:
 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_is_error { false };
     bool m_have_storage { false };
     bool m_have_storage { false };
 };
 };