Kernel: Fix adopt_ref_if_nonnull(new T).release_nonnull() pattern

This does the exact thing as `adopt_ref`, which is a recent addition to
AK.

Note that pointers returned by a bare new (without `nothrow`) are
guaranteed not to return null, so they can safely be converted into
references.
This commit is contained in:
Daniel Bertalan 2021-06-28 15:19:25 +02:00 committed by Ali Mohammad Pur
commit 2a5d9a6944
Notes: sideshowbarker 2024-07-18 11:19:15 +09:00
4 changed files with 4 additions and 5 deletions

View file

@ -15,7 +15,7 @@ namespace Kernel {
UNMAP_AFTER_INIT NonnullRefPtr<FullDevice> FullDevice::must_create()
{
return adopt_ref_if_nonnull(new FullDevice).release_nonnull();
return adopt_ref(*new FullDevice);
}
UNMAP_AFTER_INIT FullDevice::FullDevice()
@ -45,5 +45,4 @@ KResultOr<size_t> FullDevice::write(FileDescription&, u64, const UserOrKernelBuf
return 0;
return ENOSPC;
}
}