1
0
Fork 0
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:
Daniel Bertalan 2025-05-17 11:22:02 +02:00 committed by Andrew Kaster
parent b559965448
commit 33dbe385ce
Notes: github-actions[bot] 2025-05-17 21:08:46 +00:00

View file

@ -205,7 +205,6 @@ private:
virtual ~CallableWrapperBase() = default;
// Note: This is not const to allow storing mutable lambdas.
virtual Out call(In...) = 0;
virtual void destroy() = 0;
virtual void init_and_swap(u8*, size_t) = 0;
virtual void const* raw_callable() const = 0;
};
@ -226,16 +225,13 @@ private:
return m_callable(forward<In>(in)...);
}
void destroy() final override
virtual ~CallableWrapper() final override
{
if constexpr (IsBlockClosure<CallableType>) {
if constexpr (Detail::HaveObjcArc)
m_callable = nullptr;
else
_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;
case FunctionKind::Outline:
VERIFY(wrapper);
// This code is a bit too clever for gcc. Pinky promise we're only deleting heap objects.
AK_IGNORE_DIAGNOSTIC("-Wfree-nonheap-object", wrapper->destroy());
delete wrapper;
break;
case FunctionKind::Block:
VERIFY(wrapper);
wrapper->destroy();
wrapper->~CallableWrapperBase();
break;
case FunctionKind::NullPointer: