AK: Remove fallible and unused WeakPtr/Weakable methods

This commit is contained in:
Jelle Raaijmakers 2026-02-25 09:43:29 +01:00 committed by Tim Flynn
parent 6f1b7c8d50
commit 3d0b2349e6
2 changed files with 5 additions and 32 deletions

View file

@ -173,16 +173,6 @@ private:
RefPtr<WeakLink> m_link; RefPtr<WeakLink> m_link;
}; };
template<typename T>
template<typename U>
inline ErrorOr<WeakPtr<U>> Weakable<T>::try_make_weak_ptr() const
{
if (!m_link)
m_link = TRY(adopt_nonnull_ref_or_enomem(new (nothrow) WeakLink(const_cast<T&>(static_cast<T const&>(*this)))));
return WeakPtr<U>(m_link);
}
template<typename T> template<typename T>
struct Formatter<WeakPtr<T>> : Formatter<T const*> { struct Formatter<WeakPtr<T>> : Formatter<T const*> {
ErrorOr<void> format(FormatBuilder& builder, WeakPtr<T> const& value) ErrorOr<void> format(FormatBuilder& builder, WeakPtr<T> const& value)
@ -191,21 +181,6 @@ struct Formatter<WeakPtr<T>> : Formatter<T const*> {
} }
}; };
template<typename T>
ErrorOr<WeakPtr<T>> try_make_weak_ptr_if_nonnull(T const* ptr)
{
if (ptr) {
return ptr->template try_make_weak_ptr<T>();
}
return WeakPtr<T> {};
}
template<typename T>
WeakPtr<T> make_weak_ptr_if_nonnull(T const* ptr)
{
return MUST(try_make_weak_ptr_if_nonnull(ptr));
}
template<typename T> template<typename T>
struct Traits<WeakPtr<T>> : public DefaultTraits<WeakPtr<T>> { struct Traits<WeakPtr<T>> : public DefaultTraits<WeakPtr<T>> {
using PeekType = T*; using PeekType = T*;

View file

@ -6,10 +6,8 @@
#pragma once #pragma once
#include <AK/Assertions.h>
#include <AK/RefCounted.h> #include <AK/RefCounted.h>
#include <AK/RefPtr.h> #include <AK/RefPtr.h>
#include <AK/StdLibExtras.h>
namespace AK { namespace AK {
@ -61,11 +59,11 @@ public:
template<typename U = T> template<typename U = T>
WeakPtr<U> make_weak_ptr() const WeakPtr<U> make_weak_ptr() const
{ {
return MUST(try_make_weak_ptr<U>()); if (!m_link)
} m_link = adopt_ref(*new (nothrow) WeakLink(const_cast<T&>(static_cast<T const&>(*this))));
template<typename U = T> return m_link;
ErrorOr<WeakPtr<U>> try_make_weak_ptr() const; }
protected: protected:
Weakable() = default; Weakable() = default;
@ -75,7 +73,7 @@ protected:
revoke_weak_ptrs(); revoke_weak_ptrs();
} }
void revoke_weak_ptrs() void revoke_weak_ptrs() const
{ {
if (auto link = move(m_link)) if (auto link = move(m_link))
link->revoke(); link->revoke();