Skip to content

armgit / moli

Public Imported from GitHub
0

Best headless browser for AI agents. Lite, Fast, High-Compatibility. Built in Rust

perf(style): reuse cached owner import metadata

ldm0acf1eb859ac0
diff --git a/moli-renderer-v8/src/style_engine/source/shared_cache.rs b/moli-renderer-v8/src/style_engine/source/shared_cache.rs
index c12f03956..e4b8a7489 100644
--- a/moli-renderer-v8/src/style_engine/source/shared_cache.rs
+++ b/moli-renderer-v8/src/style_engine/source/shared_cache.rs
@@ -99,7 +99,11 @@ impl SharedStyleSourceContents {
Arc::clone(&self.source_metadata.font_faces)
}
- pub(super) fn import_urls(&self) -> Arc<[url::Url]> {
+ pub(super) fn import_urls(&self) -> &[url::Url] {
+ self.source_metadata.import_urls.as_ref()
+ }
+
+ pub(super) fn import_urls_handle(&self) -> Arc<[url::Url]> {
Arc::clone(&self.source_metadata.import_urls)
}
diff --git a/moli-renderer-v8/src/style_engine/source/store.rs b/moli-renderer-v8/src/style_engine/source/store.rs
index 52abf400b..041fb9961 100644
--- a/moli-renderer-v8/src/style_engine/source/store.rs
+++ b/moli-renderer-v8/src/style_engine/source/store.rs
@@ -12,7 +12,6 @@ use super::super::{
source_id::{StyleScopeId, StyleSourceId, StyleSourceKind},
source_key::{StyleSourceKey, StyleSourceSetKey},
};
-use super::imports::stylesheet_top_level_import_urls;
use super::shared_cache::{SharedStyleSourceContents, shared_style_source_contents};
use crate::{
document_runtime::DomHandle, protocol_types::EmulatedMediaOverrides,
@@ -86,7 +85,6 @@ pub(in crate::style_engine) struct StyleSourceMetadata {
pub(crate) struct OwnerStyleSheetSource {
owner: DomHandle,
source: StyloStylesheetSource,
- import_urls: StdArc<[url::Url]>,
}
impl StyloStylesheetSource {
@@ -375,7 +373,7 @@ impl StyloStylesheetSource {
pub(crate) fn import_urls(&self) -> StdArc<[url::Url]> {
match &self.contents {
- StyloStylesheetSourceContents::Text { shared } => shared.import_urls(),
+ StyloStylesheetSourceContents::Text { shared } => shared.import_urls_handle(),
StyloStylesheetSourceContents::Live { stylesheet, .. } => {
let guard = stylesheet.shared_lock.read();
let mut urls = Vec::new();
@@ -544,20 +542,8 @@ impl StylesheetFontFaceDescriptor {
impl OwnerStyleSheetSource {
pub(crate) fn new(owner: DomHandle, css_text: String, parser_base: url::Url) -> Self {
let source = StyloStylesheetSource::new(css_text, parser_base);
- let processing_contents = source
- .processing_contents()
- .expect("owner processing source must remain text-backed");
- let import_urls = stylesheet_top_level_import_urls(
- processing_contents.css_text(),
- source.base_url(),
- false,
- )
- .unwrap_or_default();
- Self {
- owner,
- source,
- import_urls: StdArc::from(import_urls),
- }
+ debug_assert!(source.processing_contents().is_some());
+ Self { owner, source }
}
pub(in crate::style_engine) fn matches_processing_input(
@@ -584,7 +570,10 @@ impl OwnerStyleSheetSource {
}
pub(crate) fn import_urls(&self) -> &[url::Url] {
- self.import_urls.as_ref()
+ self.source
+ .processing_contents()
+ .expect("owner processing source must remain text-backed")
+ .import_urls()
}
pub(crate) fn font_faces(&self) -> StdArc<[StylesheetFontFaceDescriptor]> {