mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-08-20 01:11:07 +00:00
LibWeb: Use bitmaps for important/inherited bits in StyleProperties
This avoids padding the style value array, shrinking StyleProperties from 4368 bytes to 2288 bytes per instance.
This commit is contained in:
parent
c288bfb404
commit
b42b7c8dd0
Notes:
github-actions[bot]
2024-08-02 18:38:41 +00:00
Author: https://github.com/awesomekling
Commit: b42b7c8dd0
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/935
5 changed files with 122 additions and 74 deletions
|
|
@ -15,6 +15,7 @@
|
|||
#include <LibWeb/CSS/ComputedValues.h>
|
||||
#include <LibWeb/CSS/LengthBox.h>
|
||||
#include <LibWeb/CSS/PropertyID.h>
|
||||
#include <LibWeb/CSS/StyleProperty.h>
|
||||
|
||||
namespace Web::CSS {
|
||||
|
||||
|
|
@ -23,41 +24,31 @@ public:
|
|||
StyleProperties() = default;
|
||||
|
||||
static NonnullRefPtr<StyleProperties> create() { return adopt_ref(*new StyleProperties); }
|
||||
NonnullRefPtr<StyleProperties> clone() const;
|
||||
|
||||
template<typename Callback>
|
||||
inline void for_each_property(Callback callback) const
|
||||
{
|
||||
for (size_t i = 0; i < m_property_values.size(); ++i) {
|
||||
if (m_property_values[i].style)
|
||||
callback((CSS::PropertyID)i, *m_property_values[i].style);
|
||||
if (m_property_values[i])
|
||||
callback((CSS::PropertyID)i, *m_property_values[i]);
|
||||
}
|
||||
}
|
||||
|
||||
enum class Important {
|
||||
No,
|
||||
Yes
|
||||
};
|
||||
|
||||
enum class Inherited {
|
||||
No,
|
||||
Yes
|
||||
};
|
||||
|
||||
struct StyleValueAndMetadata {
|
||||
RefPtr<StyleValue const> style;
|
||||
Important important { Important::No };
|
||||
Inherited inherited { Inherited::No };
|
||||
};
|
||||
using PropertyValues = Array<StyleValueAndMetadata, to_underlying(CSS::last_property_id) + 1>;
|
||||
|
||||
auto& properties() { return m_property_values; }
|
||||
auto const& properties() const { return m_property_values; }
|
||||
static constexpr size_t number_of_properties = to_underlying(CSS::last_property_id) + 1;
|
||||
|
||||
HashMap<CSS::PropertyID, NonnullRefPtr<StyleValue const>> const& animated_property_values() const { return m_animated_property_values; }
|
||||
void reset_animated_properties();
|
||||
|
||||
bool is_property_important(CSS::PropertyID property_id) const;
|
||||
bool is_property_inherited(CSS::PropertyID property_id) const;
|
||||
void set_property_important(CSS::PropertyID, Important);
|
||||
void set_property_inherited(CSS::PropertyID, Inherited);
|
||||
|
||||
void set_property(CSS::PropertyID, NonnullRefPtr<StyleValue const> value, Inherited = Inherited::No, Important = Important::No);
|
||||
void set_animated_property(CSS::PropertyID, NonnullRefPtr<StyleValue const> value);
|
||||
|
|
@ -192,7 +183,10 @@ private:
|
|||
// FIXME: This needs protection from GC!
|
||||
JS::GCPtr<CSS::CSSStyleDeclaration const> m_animation_name_source;
|
||||
|
||||
PropertyValues m_property_values;
|
||||
Array<RefPtr<CSS::StyleValue const>, number_of_properties> m_property_values;
|
||||
Array<u8, ceil_div(number_of_properties, 8uz)> m_property_important {};
|
||||
Array<u8, ceil_div(number_of_properties, 8uz)> m_property_inherited {};
|
||||
|
||||
HashMap<CSS::PropertyID, NonnullRefPtr<StyleValue const>> m_animated_property_values;
|
||||
|
||||
Optional<CSS::Overflow> overflow(CSS::PropertyID) const;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue