mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-04-25 14:05:15 +00:00
This patch introduces the StyleComputer::RuleCache, which divides all of our (author) CSS rules into buckets. Currently, there are two buckets: - Rules where a specific class must be present. - All other rules. This allows us to check a significantly smaller set of rules for each element, since we can skip over any rule that requires a class attribute not present on the element. This takes the typical numer of rules tested per element on Discord from ~16000 to ~550. :^) We can definitely improve the cache invalidation. It currently happens too often due to media queries. And we also need to make sure we invalidate when mutating style through CSSOM APIs.
45 lines
1.2 KiB
C++
45 lines
1.2 KiB
C++
/*
|
||
* Copyright (c) 2020, Andreas Kling <kling@serenityos.org>
|
||
*
|
||
* SPDX-License-Identifier: BSD-2-Clause
|
||
*/
|
||
|
||
#include <LibWeb/CSS/StyleSheetList.h>
|
||
#include <LibWeb/DOM/Document.h>
|
||
|
||
namespace Web::CSS {
|
||
|
||
void StyleSheetList::add_sheet(NonnullRefPtr<CSSStyleSheet> sheet)
|
||
{
|
||
VERIFY(!m_sheets.contains_slow(sheet));
|
||
m_sheets.append(move(sheet));
|
||
|
||
++m_generation;
|
||
m_document.invalidate_style();
|
||
}
|
||
|
||
void StyleSheetList::remove_sheet(CSSStyleSheet& sheet)
|
||
{
|
||
m_sheets.remove_first_matching([&](auto& entry) { return &*entry == &sheet; });
|
||
|
||
++m_generation;
|
||
m_document.invalidate_style();
|
||
}
|
||
|
||
StyleSheetList::StyleSheetList(DOM::Document& document)
|
||
: m_document(document)
|
||
{
|
||
}
|
||
|
||
// https://www.w3.org/TR/cssom/#ref-for-dfn-supported-property-indices%E2%91%A1
|
||
bool StyleSheetList::is_supported_property_index(u32 index) const
|
||
{
|
||
// The object’s supported property indices are the numbers in the range zero to one less than the number of CSS style sheets represented by the collection.
|
||
// If there are no such CSS style sheets, then there are no supported property indices.
|
||
if (m_sheets.is_empty())
|
||
return false;
|
||
|
||
return index < m_sheets.size();
|
||
}
|
||
|
||
}
|