diff --git a/AK/Variant.h b/AK/Variant.h index af6b649105..83c884d349 100644 --- a/AK/Variant.h +++ b/AK/Variant.h @@ -46,7 +46,7 @@ struct Variant; template struct Variant { static constexpr auto current_index = VariantIndexOf {}(); - static void delete_(IndexType id, void* data) + ALWAYS_INLINE static void delete_(IndexType id, void* data) { if (id == current_index) bit_cast(data)->~F(); @@ -54,7 +54,7 @@ struct Variant { Variant::delete_(id, data); } - static void move_(IndexType old_id, void* old_data, void* new_data) + ALWAYS_INLINE static void move_(IndexType old_id, void* old_data, void* new_data) { if (old_id == current_index) new (new_data) F(move(*bit_cast(old_data))); @@ -62,10 +62,10 @@ struct Variant { Variant::move_(old_id, old_data, new_data); } - static void copy_(IndexType old_id, const void* old_data, void* new_data) + ALWAYS_INLINE static void copy_(IndexType old_id, const void* old_data, void* new_data) { if (old_id == current_index) - new (new_data) F(*bit_cast(old_data)); + new (new_data) F(*bit_cast(old_data)); else Variant::copy_(old_id, old_data, new_data); } @@ -73,15 +73,15 @@ struct Variant { template struct Variant { - static void delete_(IndexType, void*) { } - static void move_(IndexType, void*, void*) { } - static void copy_(IndexType, const void*, void*) { } + ALWAYS_INLINE static void delete_(IndexType, void*) { } + ALWAYS_INLINE static void move_(IndexType, void*, void*) { } + ALWAYS_INLINE static void copy_(IndexType, const void*, void*) { } }; template struct VisitImpl { template - static constexpr decltype(auto) visit(IndexType id, const void* data, Visitor&& visitor) requires(CurrentIndex < sizeof...(Ts)) + ALWAYS_INLINE static constexpr decltype(auto) visit(IndexType id, const void* data, Visitor&& visitor) requires(CurrentIndex < sizeof...(Ts)) { using T = typename TypeList::template Type; @@ -104,22 +104,22 @@ struct VariantConstructTag { template struct VariantConstructors { - VariantConstructors(T&& t) + ALWAYS_INLINE VariantConstructors(T&& t) { internal_cast().clear_without_destruction(); internal_cast().set(move(t), VariantNoClearTag {}); } - VariantConstructors(const T& t) + ALWAYS_INLINE VariantConstructors(const T& t) { internal_cast().clear_without_destruction(); internal_cast().set(t, VariantNoClearTag {}); } - VariantConstructors() { } + ALWAYS_INLINE VariantConstructors() { } private: - [[nodiscard]] Base& internal_cast() + [[nodiscard]] ALWAYS_INLINE Base& internal_cast() { // Warning: Internal type shenanigans - VariantsConstrutors <- Base // Not the other way around, so be _really_ careful not to cause issues. @@ -210,7 +210,7 @@ public: template friend struct Variant; - Variant(const Variant& old) + ALWAYS_INLINE Variant(const Variant& old) : Detail::MergeAndDeduplicatePacks>...>() , m_data {} , m_index(old.m_index) @@ -222,7 +222,7 @@ public: // so if a variant containing an int is moved from, it will still contain that int // and if a variant with a nontrivial move ctor is moved from, it may or may not be valid // but it will still contain the "moved-from" state of the object it previously contained. - Variant(Variant&& old) + ALWAYS_INLINE Variant(Variant&& old) : Detail::MergeAndDeduplicatePacks>...>() , m_data {} , m_index(old.m_index) @@ -230,19 +230,19 @@ public: Helper::move_(old.m_index, old.m_data, m_data); } - ~Variant() + ALWAYS_INLINE ~Variant() { Helper::delete_(m_index, m_data); } - Variant& operator=(const Variant& other) + ALWAYS_INLINE Variant& operator=(const Variant& other) { m_index = other.m_index; Helper::copy_(other.m_index, other.m_data, m_data); return *this; } - Variant& operator=(Variant&& other) + ALWAYS_INLINE Variant& operator=(Variant&& other) { m_index = other.m_index; Helper::move_(other.m_index, other.m_data, m_data); @@ -305,14 +305,14 @@ public: } template - decltype(auto) visit(Fs&&... functions) + ALWAYS_INLINE decltype(auto) visit(Fs&&... functions) { Visitor visitor { forward(functions)... }; return VisitHelper::visit(m_index, m_data, move(visitor)); } template - decltype(auto) visit(Fs&&... functions) const + ALWAYS_INLINE decltype(auto) visit(Fs&&... functions) const { Visitor visitor { forward(functions)... }; return VisitHelper::visit(m_index, m_data, move(visitor)); @@ -357,7 +357,7 @@ private: { } - void clear_without_destruction() + ALWAYS_INLINE void clear_without_destruction() { __builtin_memset(m_data, 0, data_size); m_index = invalid_index; @@ -373,10 +373,10 @@ private: using Fs::operator()...; }; - alignas(data_alignment) u8 m_data[data_size]; // Note: Make sure not to default-initialize! // VariantConstructors::VariantConstructors(T) will set this to the correct value // So default-constructing to anything will leave the first initialization with that value instead of the correct one. + alignas(data_alignment) u8 m_data[data_size]; IndexType m_index; };