Skip to content

Truly independent web browser

LibWeb: Compare only the longhands of unshared style groups

Andreas Kling3a3b63637275
diff --git a/Libraries/LibWeb/Rust/src/css/computed_values.rs b/Libraries/LibWeb/Rust/src/css/computed_values.rs
index 33be799c0ce..46ebec192b1 100644
--- a/Libraries/LibWeb/Rust/src/css/computed_values.rs
+++ b/Libraries/LibWeb/Rust/src/css/computed_values.rs
@@ -4399,11 +4399,33 @@ pub(crate) struct GroupValueLayout {
const GROUP_VALUE_LAYOUT: GroupValueLayout = GroupValueLayout::compute();
+/// Per group, the longhands whose values it holds, one bit per longhand from the first: all but those
+/// in the inherited bits and the logical aliases, which map elsewhere.
+const GROUP_LONGHANDS: [[u64; crate::css::property_metadata::LONGHAND_WORD_COUNT]; group_index::COUNT] = {
+ let mut groups = [[0; crate::css::property_metadata::LONGHAND_WORD_COUNT]; group_index::COUNT];
+ let mut longhand = 0;
+ while longhand < LONGHAND_COUNT {
+ let property = crate::css::property_metadata::FIRST_LONGHAND_PROPERTY_ID + longhand as u16;
+ let group = GROUP_VALUE_LAYOUT.places[longhand].group;
+ if !is_logical_alias(property) && group != LonghandPlace::NONE.group && group != LonghandPlace::BITS_GROUP {
+ groups[group as usize][longhand / 64] |= 1 << (longhand % 64);
+ }
+ longhand += 1;
+ }
+ groups
+};
+
impl GroupValueLayout {
pub(crate) fn get() -> &'static Self {
&GROUP_VALUE_LAYOUT
}
+ /// The longhands whose values each group holds, one bit per longhand from the first.
+ pub(crate) fn group_longhands()
+ -> &'static [[u64; crate::css::property_metadata::LONGHAND_WORD_COUNT]; group_index::COUNT] {
+ &GROUP_LONGHANDS
+ }
+
const fn compute() -> Self {
use crate::css::property_metadata::{
FIRST_INHERITED_PROPERTY_ID, FIRST_LONGHAND_PROPERTY_ID, LAST_INHERITED_PROPERTY_ID,
diff --git a/Libraries/LibWeb/Rust/src/css/style/computed.rs b/Libraries/LibWeb/Rust/src/css/style/computed.rs
index 04d3f9a1d4a..7ce307f4193 100644
--- a/Libraries/LibWeb/Rust/src/css/style/computed.rs
+++ b/Libraries/LibWeb/Rust/src/css/style/computed.rs
@@ -108,6 +108,23 @@ impl SharedLonghands {
// NB: The inherited bits are no group's: the records' values of them compare by value.
layout.holds_value(longhand) && place.bit_field().is_none() && self.shared_groups & (1 << place.group()) != 0
}
+
+ /// The longhands whose values the records may hold differently, one bit per longhand from the
+ /// first: those in a group they do not share, and those that map elsewhere or hold no value of a
+ /// group.
+ pub(crate) fn longhands_to_compare(self) -> [u64; crate::css::property_metadata::LONGHAND_WORD_COUNT] {
+ use crate::css::property_metadata::LONGHAND_WORD_COUNT;
+ let group_longhands = crate::css::computed_values::GroupValueLayout::group_longhands();
+ let mut longhands = [u64::MAX; LONGHAND_WORD_COUNT];
+ for (group, group_words) in group_longhands.iter().enumerate() {
+ if self.shared_groups & (1 << group) != 0 {
+ for (word, group_word) in longhands.iter_mut().zip(group_words) {
+ *word &= !group_word;
+ }
+ }
+ }
+ longhands
+ }
}
impl<'a> ViewLonghands<'a> {
diff --git a/Libraries/LibWeb/Rust/src/css/style/style_invalidation.rs b/Libraries/LibWeb/Rust/src/css/style/style_invalidation.rs
index 6772709a28d..24fec83b0bb 100644
--- a/Libraries/LibWeb/Rust/src/css/style/style_invalidation.rs
+++ b/Libraries/LibWeb/Rust/src/css/style/style_invalidation.rs
@@ -1235,7 +1235,21 @@ fn record_move_damage(
&& old_direction == new_direction
});
let mut effective_changed = [false; NUMBER_OF_LONGHAND_PROPERTIES];
- for (index, changed) in effective_changed.iter_mut().enumerate() {
+ let to_compare = shared.map_or(
+ [u64::MAX; crate::css::property_metadata::LONGHAND_WORD_COUNT],
+ super::computed::SharedLonghands::longhands_to_compare,
+ );
+ let indices = to_compare.into_iter().enumerate().flat_map(|(word_index, mut word)| {
+ std::iter::from_fn(move || {
+ let bit = word.trailing_zeros() as usize;
+ (word != 0).then(|| {
+ word &= word - 1;
+ word_index * 64 + bit
+ })
+ })
+ });
+ for index in indices.take_while(|&index| index < NUMBER_OF_LONGHAND_PROPERTIES) {
+ let changed = &mut effective_changed[index];
let property = FIRST_LONGHAND_PROPERTY_ID + index as u16;
let old_physical = if property_metadata::longhand_is_logical_alias(property) {
crate::css::style_compute::map_logical_alias_to_physical(property, old_writing_mode, old_direction)