mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-06-08 05:27:14 +09:00
AK: Replace CallableWrapper::destroy()
with a destructor
Previously, heap-allocated `CallableWrapper` objects were destroyed in a very roundabout way: `AK::Function` would call a virtual `destroy()` method, which then invoked delete manually. This was unnecessary, since `CallableWrapper` already has a virtual destructor — deleting it through a `CallableWrapperBase*` correctly calls the closure's destructor. This fixes GCC `-Wfree-nonheap-object` false positive warnings (#4721) and coincidentally removes 8 KB of vtable entries (and the corresponding relative relocations) from LibJS.
This commit is contained in:
parent
b559965448
commit
33dbe385ce
Notes:
github-actions[bot]
2025-05-17 21:08:46 +00:00
Author: https://github.com/BertalanD
Commit: 33dbe385ce
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/4792
Reviewed-by: https://github.com/ADKaster ✅
1 changed files with 2 additions and 8 deletions
|
@ -205,7 +205,6 @@ private:
|
||||||
virtual ~CallableWrapperBase() = default;
|
virtual ~CallableWrapperBase() = default;
|
||||||
// Note: This is not const to allow storing mutable lambdas.
|
// Note: This is not const to allow storing mutable lambdas.
|
||||||
virtual Out call(In...) = 0;
|
virtual Out call(In...) = 0;
|
||||||
virtual void destroy() = 0;
|
|
||||||
virtual void init_and_swap(u8*, size_t) = 0;
|
virtual void init_and_swap(u8*, size_t) = 0;
|
||||||
virtual void const* raw_callable() const = 0;
|
virtual void const* raw_callable() const = 0;
|
||||||
};
|
};
|
||||||
|
@ -226,16 +225,13 @@ private:
|
||||||
return m_callable(forward<In>(in)...);
|
return m_callable(forward<In>(in)...);
|
||||||
}
|
}
|
||||||
|
|
||||||
void destroy() final override
|
virtual ~CallableWrapper() final override
|
||||||
{
|
{
|
||||||
if constexpr (IsBlockClosure<CallableType>) {
|
if constexpr (IsBlockClosure<CallableType>) {
|
||||||
if constexpr (Detail::HaveObjcArc)
|
if constexpr (Detail::HaveObjcArc)
|
||||||
m_callable = nullptr;
|
m_callable = nullptr;
|
||||||
else
|
else
|
||||||
_Block_release(m_callable);
|
_Block_release(m_callable);
|
||||||
} else {
|
|
||||||
// This code is a bit too clever for gcc. Pinky promise we're only deleting heap objects.
|
|
||||||
AK_IGNORE_DIAGNOSTIC("-Wfree-nonheap-object", delete this);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -298,12 +294,10 @@ private:
|
||||||
break;
|
break;
|
||||||
case FunctionKind::Outline:
|
case FunctionKind::Outline:
|
||||||
VERIFY(wrapper);
|
VERIFY(wrapper);
|
||||||
// This code is a bit too clever for gcc. Pinky promise we're only deleting heap objects.
|
delete wrapper;
|
||||||
AK_IGNORE_DIAGNOSTIC("-Wfree-nonheap-object", wrapper->destroy());
|
|
||||||
break;
|
break;
|
||||||
case FunctionKind::Block:
|
case FunctionKind::Block:
|
||||||
VERIFY(wrapper);
|
VERIFY(wrapper);
|
||||||
wrapper->destroy();
|
|
||||||
wrapper->~CallableWrapperBase();
|
wrapper->~CallableWrapperBase();
|
||||||
break;
|
break;
|
||||||
case FunctionKind::NullPointer:
|
case FunctionKind::NullPointer:
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue