Truly independent web browser
LibWeb: Detach unresolved values from the text of their sheet
Shannon Booth908d0c43f2a4
diff --git a/Libraries/LibWeb/Rust/src/css/css_tokenizer.rs b/Libraries/LibWeb/Rust/src/css/css_tokenizer.rsindex c7a3bf07ad0..5033974e829 100644--- a/Libraries/LibWeb/Rust/src/css/css_tokenizer.rs+++ b/Libraries/LibWeb/Rust/src/css/css_tokenizer.rs@@ -521,11 +521,16 @@ impl SourceStorage {Self::Utf16(units) => TokenizerInput::Utf16(units),}}++ fn len(&self) -> usize {+ self.as_input().len()+ }}/// Moves the text that values outliving their parse keep out of the storage they share with the rest of the sheet, so/// that keeping them does not keep the whole sheet's text alive. The values are walked twice: once to find the span of-/// each storage they keep, and once to point them into one copy of that span.+/// each storage they keep, and once to point them into one copy of that span (or the storage itself, when they keep all+/// of it).#[derive(Default)]pub(crate) struct TextDetacher {sources: DetachedSpans<SourceStorage>,@@ -541,13 +546,21 @@ impl TextDetacher {let mut detacher = Self::default();walk(&mut detacher);for (storage, span, copy) in &mut detacher.sources {- *copy = Some(Arc::new(match storage.as_ref() {- SourceStorage::Ascii(units) => SourceStorage::Ascii(units[span.clone()].into()),- SourceStorage::Utf16(units) => SourceStorage::Utf16(units[span.clone()].into()),- }));+ *copy = Some(if *span == (0..storage.len()) {+ Arc::clone(storage)+ } else {+ Arc::new(match storage.as_ref() {+ SourceStorage::Ascii(units) => SourceStorage::Ascii(units[span.clone()].into()),+ SourceStorage::Utf16(units) => SourceStorage::Utf16(units[span.clone()].into()),+ })+ });}for (storage, span, copy) in &mut detacher.strings {- *copy = Some(storage[span.clone()].into());+ *copy = Some(if *span == (0..storage.len()) {+ Arc::clone(storage)+ } else {+ storage[span.clone()].into()+ });}walk(&mut detacher);}diff --git a/Libraries/LibWeb/Rust/src/css/style_value.rs b/Libraries/LibWeb/Rust/src/css/style_value.rsindex 1d596a3a7e7..9dc68a29086 100644--- a/Libraries/LibWeb/Rust/src/css/style_value.rs+++ b/Libraries/LibWeb/Rust/src/css/style_value.rs@@ -16,7 +16,8 @@ use std::ffi::c_void;use std::sync::Arc;use crate::css::css_tokenizer::{- ParserSource, ParserTokenKind, SourcePosition, TokenizerInput, trim_component_value_boundary_whitespace,+ ParserSource, ParserTokenKind, SourcePosition, TextDetacher, TokenizerInput,+ trim_component_value_boundary_whitespace,};use crate::css::parser::component_value::{ComponentKind, ComponentSerializationMode, ComponentValue, ComponentValueList, ComponentValueSlice,@@ -45,6 +46,7 @@ impl RetainedComponentValueList {let values = values.into();let token_count = values.token_count;let mut values = values.into_vec().into_boxed_slice();+ TextDetacher::detach(|detacher| values.iter_mut().for_each(|value| value.detach(detacher)));let result = Self {pointer: values.as_mut_ptr().cast(),length: values.len(),