mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 16:27:35 +00:00
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:
parent
9b1157924b
commit
2a5d9a6944
4 changed files with 4 additions and 5 deletions
|
@ -15,7 +15,7 @@ namespace Kernel {
|
||||||
|
|
||||||
UNMAP_AFTER_INIT NonnullRefPtr<FullDevice> FullDevice::must_create()
|
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()
|
UNMAP_AFTER_INIT FullDevice::FullDevice()
|
||||||
|
@ -45,5 +45,4 @@ KResultOr<size_t> FullDevice::write(FileDescription&, u64, const UserOrKernelBuf
|
||||||
return 0;
|
return 0;
|
||||||
return ENOSPC;
|
return ENOSPC;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,7 +17,7 @@ namespace Kernel {
|
||||||
|
|
||||||
UNMAP_AFTER_INIT NonnullRefPtr<MemoryDevice> MemoryDevice::must_create()
|
UNMAP_AFTER_INIT NonnullRefPtr<MemoryDevice> MemoryDevice::must_create()
|
||||||
{
|
{
|
||||||
return adopt_ref_if_nonnull(new MemoryDevice).release_nonnull();
|
return adopt_ref(*new MemoryDevice);
|
||||||
}
|
}
|
||||||
|
|
||||||
UNMAP_AFTER_INIT MemoryDevice::MemoryDevice()
|
UNMAP_AFTER_INIT MemoryDevice::MemoryDevice()
|
||||||
|
|
|
@ -13,7 +13,7 @@ namespace Kernel {
|
||||||
|
|
||||||
UNMAP_AFTER_INIT NonnullRefPtr<RandomDevice> RandomDevice::must_create()
|
UNMAP_AFTER_INIT NonnullRefPtr<RandomDevice> RandomDevice::must_create()
|
||||||
{
|
{
|
||||||
return adopt_ref_if_nonnull(new RandomDevice).release_nonnull();
|
return adopt_ref(*new RandomDevice);
|
||||||
}
|
}
|
||||||
|
|
||||||
UNMAP_AFTER_INIT RandomDevice::RandomDevice()
|
UNMAP_AFTER_INIT RandomDevice::RandomDevice()
|
||||||
|
|
|
@ -14,7 +14,7 @@ namespace Kernel {
|
||||||
|
|
||||||
UNMAP_AFTER_INIT NonnullRefPtr<ZeroDevice> ZeroDevice::must_create()
|
UNMAP_AFTER_INIT NonnullRefPtr<ZeroDevice> ZeroDevice::must_create()
|
||||||
{
|
{
|
||||||
return adopt_ref_if_nonnull(new ZeroDevice).release_nonnull();
|
return adopt_ref(*new ZeroDevice);
|
||||||
}
|
}
|
||||||
|
|
||||||
UNMAP_AFTER_INIT ZeroDevice::ZeroDevice()
|
UNMAP_AFTER_INIT ZeroDevice::ZeroDevice()
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue