1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-14 09:04:59 +00:00

AK+Kernel: Rename try_make_weak_ptr to make_weak_ptr_if_nonnull

This matches the likes of the adopt_{own, ref}_if_nonnull family and
also frees up the name to allow us to eventually add OOM-fallible
versions of these functions.
This commit is contained in:
Idan Horowitz 2022-02-13 20:47:36 +02:00 committed by Andreas Kling
parent bfe1bd9726
commit d6ea6c39a7
6 changed files with 6 additions and 6 deletions

View file

@ -168,7 +168,7 @@ struct Formatter<WeakPtr<T>> : Formatter<const T*> {
};
template<typename T>
WeakPtr<T> try_make_weak_ptr(const T* ptr)
WeakPtr<T> make_weak_ptr_if_nonnull(const T* ptr)
{
if (ptr) {
return ptr->template make_weak_ptr<T>();

View file

@ -229,7 +229,7 @@ struct Formatter<WeakPtr<T>> : Formatter<const T*> {
};
template<typename T>
WeakPtr<T> try_make_weak_ptr(const T* ptr)
WeakPtr<T> make_weak_ptr_if_nonnull(const T* ptr)
{
if (ptr) {
return ptr->template make_weak_ptr<T>();

View file

@ -404,7 +404,7 @@ static ErrorOr<LoadResult> load_elf_object(NonnullOwnPtr<Memory::AddressSpace> n
load_base_address,
elf_image.entry().offset(load_offset).get(),
executable_size,
AK::try_make_weak_ptr(master_tls_region),
AK::make_weak_ptr_if_nonnull(master_tls_region),
master_tls_size,
master_tls_alignment,
stack_region->make_weak_ptr()

View file

@ -13,7 +13,7 @@ namespace Core {
ChildEvent::ChildEvent(Type type, Object& child, Object* insertion_before_child)
: Core::Event(type)
, m_child(child.make_weak_ptr())
, m_insertion_before_child(AK::try_make_weak_ptr(insertion_before_child))
, m_insertion_before_child(AK::make_weak_ptr_if_nonnull(insertion_before_child))
{
}

View file

@ -214,7 +214,7 @@ void Action::set_checked(bool checked)
void Action::set_group(Badge<ActionGroup>, ActionGroup* group)
{
m_action_group = AK::try_make_weak_ptr(group);
m_action_group = AK::make_weak_ptr_if_nonnull(group);
}
void Action::set_icon(const Gfx::Bitmap* icon)

View file

@ -17,7 +17,7 @@ namespace CommonActions {
NonnullRefPtr<Action> make_about_action(const String& app_name, const Icon& app_icon, Window* parent)
{
auto weak_parent = AK::try_make_weak_ptr<Window>(parent);
auto weak_parent = AK::make_weak_ptr_if_nonnull<Window>(parent);
auto action = Action::create(String::formatted("&About {}", app_name), app_icon.bitmap_for_size(16), [=](auto&) {
AboutDialog::show(app_name, app_icon.bitmap_for_size(32), weak_parent.ptr());
});