Ver código fonte

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 anos atrás
pai
commit
1d843c46eb
1 arquivos alterados com 4 adições e 2 exclusões
  1. 4 2
      Kernel/KResult.h

+ 4 - 2
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 };
 };