1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 07:47:48 +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

@ -176,6 +176,9 @@ namespace Web::Bindings {
NodeWrapper* wrap(JS::GlobalObject& global_object, DOM::Node& node)
{
if (node.wrapper())
return static_cast<NodeWrapper*>(node.wrapper());
if (is<DOM::Document>(node))
return static_cast<NodeWrapper*>(wrap_impl(global_object, verify_cast<DOM::Document>(node)));
if (is<DOM::DocumentType>(node))