1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 15:27:35 +00:00

LibWeb: Add fast-paths for wrapping already-wrapped C++ objects

If a C++ object already has a JS wrapper, we don't need to go through
the expensive type checks to figure out which kind of wrapper to create.
Instead, just return the wrapper we already have!

This gives a noticeable increase in smoothness on Acid3, where ~10% of
CPU time was previously spent doing RTTI type checks in wrap(). With
these changes, it's down to ~1%.
This commit is contained in:
Andreas Kling 2022-03-27 03:19:32 +02:00
parent 5c5e4b5ae5
commit 269f9c6863
3 changed files with 9 additions and 0 deletions

View file

@ -22,6 +22,9 @@ namespace Web::Bindings {
EventWrapper* wrap(JS::GlobalObject& global_object, DOM::Event& event)
{
if (event.wrapper())
return static_cast<EventWrapper*>(event.wrapper());
if (is<DOM::CustomEvent>(event))
return static_cast<CustomEventWrapper*>(wrap_impl(global_object, static_cast<DOM::CustomEvent&>(event)));
if (is<CSS::MediaQueryListEvent>(event))