mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 09:38:11 +00:00
LibWeb: Cache parsed inline style of DOM elements
Instead of invoking the CSS parser every time we compute the style for an element that has a "style" attribute, we now cache the result of parsing the inline style whenever the "style" attribute is set. This is a nice boost to relayout performance since we no longer hit the CSS parser at all.
This commit is contained in:
parent
867faa5d44
commit
d65bebd8cf
4 changed files with 12 additions and 7 deletions
|
@ -26,6 +26,7 @@
|
|||
|
||||
#include <AK/StringBuilder.h>
|
||||
#include <LibWeb/CSS/Length.h>
|
||||
#include <LibWeb/CSS/Parser/CSSParser.h>
|
||||
#include <LibWeb/CSS/PropertyID.h>
|
||||
#include <LibWeb/CSS/StyleResolver.h>
|
||||
#include <LibWeb/DOM/Document.h>
|
||||
|
@ -153,13 +154,15 @@ RefPtr<Layout::Node> Element::create_layout_node(const CSS::StyleProperties* par
|
|||
|
||||
void Element::parse_attribute(const FlyString& name, const String& value)
|
||||
{
|
||||
if (name == "class") {
|
||||
if (name == HTML::AttributeNames::class_) {
|
||||
auto new_classes = value.split_view(' ');
|
||||
m_classes.clear();
|
||||
m_classes.ensure_capacity(new_classes.size());
|
||||
for (auto& new_class : new_classes) {
|
||||
m_classes.unchecked_append(new_class);
|
||||
}
|
||||
} else if (name == HTML::AttributeNames::style) {
|
||||
m_inline_style = parse_css_declaration(CSS::ParsingContext(document()), value);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue