1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-16 01:34:58 +00:00
serenity/Userland/Libraries/LibWeb/Bindings/CSSRuleWrapperFactory.cpp
Andreas Kling 269f9c6863 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%.
2022-03-27 03:21:29 +02:00

25 lines
733 B
C++

/*
* Copyright (c) 2021, Andreas Kling <kling@serenityos.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#include <AK/TypeCasts.h>
#include <LibWeb/Bindings/CSSRuleWrapper.h>
#include <LibWeb/Bindings/CSSRuleWrapperFactory.h>
#include <LibWeb/Bindings/CSSStyleRuleWrapper.h>
#include <LibWeb/CSS/CSSStyleRule.h>
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));
}
}