From 75dca629df6bbcb051cf1daf4606cf53654b2494 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Sat, 7 May 2022 12:50:54 +0200 Subject: [PATCH] AK+Kernel: Remove RefPtrTraits template param in userspace code Only the kernel actually uses RefPtrTraits, so let's not burden userspace builds with the complexity. --- AK/Forward.h | 5 +++++ AK/NonnullOwnPtr.h | 12 ++++-------- AK/NonnullRefPtr.h | 4 ++-- AK/RefPtr.h | 32 ++++++++++++++++---------------- AK/Weakable.h | 6 +++--- 5 files changed, 30 insertions(+), 29 deletions(-) diff --git a/AK/Forward.h b/AK/Forward.h index 938c9fcb8f2..cced16c5bf0 100644 --- a/AK/Forward.h +++ b/AK/Forward.h @@ -115,11 +115,16 @@ class NonnullOwnPtrVector; template class Optional; +#ifdef KERNEL template struct RefPtrTraits; template> class RefPtr; +#else +template +class RefPtr; +#endif template class OwnPtr; diff --git a/AK/NonnullOwnPtr.h b/AK/NonnullOwnPtr.h index ad374dcad58..b10ac3ddc7c 100644 --- a/AK/NonnullOwnPtr.h +++ b/AK/NonnullOwnPtr.h @@ -17,10 +17,6 @@ namespace AK { -template -class RefPtr; -template -class NonnullRefPtr; template class WeakPtr; @@ -64,14 +60,14 @@ public: template NonnullOwnPtr& operator=(NonnullOwnPtr const&) = delete; - template> - NonnullOwnPtr(RefPtr const&) = delete; + template + NonnullOwnPtr(RefPtr const&) = delete; template NonnullOwnPtr(NonnullRefPtr const&) = delete; template NonnullOwnPtr(WeakPtr const&) = delete; - template> - NonnullOwnPtr& operator=(RefPtr const&) = delete; + template + NonnullOwnPtr& operator=(RefPtr const&) = delete; template NonnullOwnPtr& operator=(NonnullRefPtr const&) = delete; template diff --git a/AK/NonnullRefPtr.h b/AK/NonnullRefPtr.h index 2aab1d65ead..021b72eb0a4 100644 --- a/AK/NonnullRefPtr.h +++ b/AK/NonnullRefPtr.h @@ -21,7 +21,7 @@ namespace AK { template class OwnPtr; -template +template class RefPtr; template @@ -40,7 +40,7 @@ ALWAYS_INLINE void unref_if_not_null(T* ptr) template class [[nodiscard]] NonnullRefPtr { - template + template friend class RefPtr; template friend class NonnullRefPtr; diff --git a/AK/RefPtr.h b/AK/RefPtr.h index 53a2fc2a8f7..01892e85271 100644 --- a/AK/RefPtr.h +++ b/AK/RefPtr.h @@ -26,9 +26,9 @@ namespace AK { template class OwnPtr; -template +template class [[nodiscard]] RefPtr { - template + template friend class RefPtr; template friend class WeakPtr; @@ -80,8 +80,8 @@ public: { } - template> - RefPtr(RefPtr&& other) requires(IsConvertible) + template + RefPtr(RefPtr&& other) requires(IsConvertible) : m_ptr(static_cast(other.leak_ref())) { } @@ -92,8 +92,8 @@ public: ref_if_not_null(m_ptr); } - template> - RefPtr(RefPtr const& other) requires(IsConvertible) + template + RefPtr(RefPtr const& other) requires(IsConvertible) : m_ptr(const_cast(static_cast(other.ptr()))) { ref_if_not_null(m_ptr); @@ -117,8 +117,8 @@ public: AK::swap(m_ptr, other.m_ptr); } - template> - void swap(RefPtr& other) requires(IsConvertible) + template + void swap(RefPtr& other) requires(IsConvertible) { AK::swap(m_ptr, other.m_ptr); } @@ -130,8 +130,8 @@ public: return *this; } - template> - ALWAYS_INLINE RefPtr& operator=(RefPtr&& other) requires(IsConvertible) + template + ALWAYS_INLINE RefPtr& operator=(RefPtr&& other) requires(IsConvertible) { RefPtr tmp { move(other) }; swap(tmp); @@ -204,8 +204,8 @@ public: return true; } - template> - ALWAYS_INLINE bool assign_if_null(RefPtr&& other) + template + ALWAYS_INLINE bool assign_if_null(RefPtr&& other) { if (this == &other) return is_null(); @@ -315,14 +315,14 @@ inline NonnullRefPtr static_ptr_cast(NonnullRefPtr const& ptr) return NonnullRefPtr(static_cast(*ptr)); } -template> +template inline RefPtr static_ptr_cast(RefPtr const& ptr) { - return RefPtr(static_cast(ptr.ptr())); + return RefPtr(static_cast(ptr.ptr())); } -template -inline void swap(RefPtr& a, RefPtr& b) requires(IsConvertible) +template +inline void swap(RefPtr& a, RefPtr& b) requires(IsConvertible) { a.swap(b); } diff --git a/AK/Weakable.h b/AK/Weakable.h index ee784aa0903..af9469ca4ed 100644 --- a/AK/Weakable.h +++ b/AK/Weakable.h @@ -30,11 +30,11 @@ class WeakLink : public RefCounted { friend class WeakPtr; public: - template> - RefPtr strong_ref() const + template + RefPtr strong_ref() const requires(IsBaseOf) { - RefPtr ref; + RefPtr ref; { if (!(m_consumers.fetch_add(1u << 1, AK::MemoryOrder::memory_order_acquire) & 1u)) {