mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-22 07:30:19 +00:00
AK: Move adopt_nonnull_ref_or_enomem() to NonnullRefPtr.h
Rewrite the implementation to not depend on OwnPtr.h. No intended behavior change.
This commit is contained in:
parent
ca6090889a
commit
ed198ee6ae
Notes:
sideshowbarker
2024-07-17 07:20:57 +09:00
Author: https://github.com/nico Commit: https://github.com/SerenityOS/serenity/commit/ed198ee6ae Pull-request: https://github.com/SerenityOS/serenity/pull/17424
2 changed files with 10 additions and 10 deletions
|
@ -226,6 +226,15 @@ inline NonnullRefPtr<T> adopt_ref(T& object)
|
|||
return NonnullRefPtr<T>(NonnullRefPtr<T>::Adopt, object);
|
||||
}
|
||||
|
||||
// Use like `adopt_nonnull_own_or_enomem(new (nothrow) T(args...))`.
|
||||
template<typename T>
|
||||
inline ErrorOr<NonnullRefPtr<T>> adopt_nonnull_ref_or_enomem(T* object)
|
||||
{
|
||||
if (!object)
|
||||
return Error::from_errno(ENOMEM);
|
||||
return NonnullRefPtr<T>(NonnullRefPtr<T>::Adopt, *object);
|
||||
}
|
||||
|
||||
template<Formattable T>
|
||||
struct Formatter<NonnullRefPtr<T>> : Formatter<T> {
|
||||
ErrorOr<void> format(FormatBuilder& builder, NonnullRefPtr<T> const& value)
|
||||
|
@ -274,6 +283,7 @@ struct Traits<NonnullRefPtr<T>> : public GenericTraits<NonnullRefPtr<T>> {
|
|||
}
|
||||
|
||||
#if USING_AK_GLOBALLY
|
||||
using AK::adopt_nonnull_ref_or_enomem;
|
||||
using AK::adopt_ref;
|
||||
using AK::make_ref_counted;
|
||||
using AK::NonnullRefPtr;
|
||||
|
|
10
AK/RefPtr.h
10
AK/RefPtr.h
|
@ -341,19 +341,9 @@ inline ErrorOr<NonnullRefPtr<T>> try_make_ref_counted(Args&&... args)
|
|||
return adopt_nonnull_ref_or_enomem(new (nothrow) T { forward<Args>(args)... });
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
inline ErrorOr<NonnullRefPtr<T>> adopt_nonnull_ref_or_enomem(T* object)
|
||||
{
|
||||
auto result = adopt_ref_if_nonnull(object);
|
||||
if (!result)
|
||||
return Error::from_errno(ENOMEM);
|
||||
return result.release_nonnull();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#if USING_AK_GLOBALLY
|
||||
using AK::adopt_nonnull_ref_or_enomem;
|
||||
using AK::adopt_ref_if_nonnull;
|
||||
using AK::RefPtr;
|
||||
using AK::static_ptr_cast;
|
||||
|
|
Loading…
Reference in a new issue