1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-26 04:27:44 +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

@ -14,6 +14,9 @@ namespace Web::Bindings {
CSSRuleWrapper* wrap(JS::GlobalObject& global_object, CSS::CSSRule& rule)
{
if (rule.wrapper())
return static_cast<CSSRuleWrapper*>(rule.wrapper());
if (is<CSS::CSSStyleRule>(rule))
return static_cast<CSSRuleWrapper*>(wrap_impl(global_object, verify_cast<CSS::CSSStyleRule>(rule)));
return static_cast<CSSRuleWrapper*>(wrap_impl(global_object, rule));

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))

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))