diff --git a/AK/NonnullRefPtr.h b/AK/NonnullRefPtr.h index 107aedc4a9..e6a7a499b1 100644 --- a/AK/NonnullRefPtr.h +++ b/AK/NonnullRefPtr.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2018-2020, Andreas Kling + * Copyright (c) 2018-2023, Andreas Kling * * SPDX-License-Identifier: BSD-2-Clause */ @@ -47,16 +47,16 @@ public: enum AdoptTag { Adopt }; - ALWAYS_INLINE NonnullRefPtr(T const& object) - : m_ptr(const_cast(&object)) + ALWAYS_INLINE NonnullRefPtr(T& object) + : m_ptr(&object) { m_ptr->ref(); } template - ALWAYS_INLINE NonnullRefPtr(U const& object) + ALWAYS_INLINE NonnullRefPtr(U& object) requires(IsConvertible) - : m_ptr(const_cast(static_cast(&object))) + : m_ptr(static_cast(&object)) { m_ptr->ref(); } @@ -79,7 +79,7 @@ public: } ALWAYS_INLINE NonnullRefPtr(NonnullRefPtr const& other) - : m_ptr(const_cast(other.ptr())) + : m_ptr(other.ptr()) { m_ptr->ref(); } @@ -87,7 +87,7 @@ public: template ALWAYS_INLINE NonnullRefPtr(NonnullRefPtr const& other) requires(IsConvertible) - : m_ptr(const_cast(static_cast(other.ptr()))) + : m_ptr(static_cast(other.ptr())) { m_ptr->ref(); } @@ -145,7 +145,7 @@ public: return *this; } - NonnullRefPtr& operator=(T const& object) + NonnullRefPtr& operator=(T& object) { NonnullRefPtr tmp { object }; swap(tmp); diff --git a/AK/RefPtr.h b/AK/RefPtr.h index 1c28a07d9a..661a345131 100644 --- a/AK/RefPtr.h +++ b/AK/RefPtr.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2018-2020, Andreas Kling + * Copyright (c) 2018-2023, Andreas Kling * * SPDX-License-Identifier: BSD-2-Clause */ @@ -35,14 +35,14 @@ public: }; RefPtr() = default; - RefPtr(T const* ptr) - : m_ptr(const_cast(ptr)) + RefPtr(T* ptr) + : m_ptr(ptr) { ref_if_not_null(m_ptr); } - RefPtr(T const& object) - : m_ptr(const_cast(&object)) + RefPtr(T& object) + : m_ptr(&object) { m_ptr->ref(); } @@ -58,7 +58,7 @@ public: } ALWAYS_INLINE RefPtr(NonnullRefPtr const& other) - : m_ptr(const_cast(other.ptr())) + : m_ptr(other.ptr()) { m_ptr->ref(); } @@ -66,7 +66,7 @@ public: template ALWAYS_INLINE RefPtr(NonnullRefPtr const& other) requires(IsConvertible) - : m_ptr(const_cast(static_cast(other.ptr()))) + : m_ptr(static_cast(other.ptr())) { m_ptr->ref(); } @@ -94,7 +94,7 @@ public: template RefPtr(RefPtr const& other) requires(IsConvertible) - : m_ptr(const_cast(static_cast(other.ptr()))) + : m_ptr(static_cast(other.ptr())) { ref_if_not_null(m_ptr); } @@ -181,14 +181,14 @@ public: return *this; } - ALWAYS_INLINE RefPtr& operator=(T const* ptr) + ALWAYS_INLINE RefPtr& operator=(T* ptr) { RefPtr tmp { ptr }; swap(tmp); return *this; } - ALWAYS_INLINE RefPtr& operator=(T const& object) + ALWAYS_INLINE RefPtr& operator=(T& object) { RefPtr tmp { object }; swap(tmp); @@ -304,13 +304,13 @@ struct Traits> : public GenericTraits> { template inline NonnullRefPtr static_ptr_cast(NonnullRefPtr const& ptr) { - return NonnullRefPtr(static_cast(*ptr)); + return NonnullRefPtr(static_cast(*ptr)); } template inline RefPtr static_ptr_cast(RefPtr const& ptr) { - return RefPtr(static_cast(ptr.ptr())); + return RefPtr(static_cast(ptr.ptr())); } template