Bug 1978217 - Record use counter data inline in StylesheetContents. r=firefox-style-system-reviewers,layout-reviewers,dshin, a=dsmith
No behavior change, but this is simpler. I want to reuse the use counters mechanism to fix this bug because it's a very trivial way of asking questions about the parsed data and we need to plumb it through the same places. Differential Revision: https://phabricator.services.mozilla.com/D258290
This commit is contained in:
committed by
dsmith@mozilla.com
parent
6dbb975108
commit
a3013fe0ae
@@ -65,6 +65,8 @@ pub struct StylesheetContents {
|
||||
pub source_map_url: RwLock<Option<String>>,
|
||||
/// This stylesheet's source URL.
|
||||
pub source_url: RwLock<Option<String>>,
|
||||
/// The use counters of the original stylesheet.
|
||||
pub use_counters: UseCounters,
|
||||
|
||||
/// We don't want to allow construction outside of this file, to guarantee
|
||||
/// that all contents are created with Arc<>.
|
||||
@@ -82,10 +84,10 @@ impl StylesheetContents {
|
||||
stylesheet_loader: Option<&dyn StylesheetLoader>,
|
||||
error_reporter: Option<&dyn ParseErrorReporter>,
|
||||
quirks_mode: QuirksMode,
|
||||
use_counters: Option<&UseCounters>,
|
||||
allow_import_rules: AllowImportRules,
|
||||
sanitization_data: Option<&mut SanitizationData>,
|
||||
) -> Arc<Self> {
|
||||
let use_counters = UseCounters::default();
|
||||
let (namespaces, rules, source_map_url, source_url) = Stylesheet::parse_rules(
|
||||
css,
|
||||
&url_data,
|
||||
@@ -94,7 +96,7 @@ impl StylesheetContents {
|
||||
stylesheet_loader,
|
||||
error_reporter,
|
||||
quirks_mode,
|
||||
use_counters,
|
||||
Some(&use_counters),
|
||||
allow_import_rules,
|
||||
sanitization_data,
|
||||
);
|
||||
@@ -107,6 +109,7 @@ impl StylesheetContents {
|
||||
quirks_mode,
|
||||
source_map_url: RwLock::new(source_map_url),
|
||||
source_url: RwLock::new(source_url),
|
||||
use_counters,
|
||||
_forbid_construction: (),
|
||||
})
|
||||
}
|
||||
@@ -137,6 +140,7 @@ impl StylesheetContents {
|
||||
quirks_mode,
|
||||
source_map_url: RwLock::new(None),
|
||||
source_url: RwLock::new(None),
|
||||
use_counters: UseCounters::default(),
|
||||
_forbid_construction: (),
|
||||
})
|
||||
}
|
||||
@@ -179,6 +183,7 @@ impl DeepCloneWithLock for StylesheetContents {
|
||||
namespaces: RwLock::new((*self.namespaces.read()).clone()),
|
||||
source_map_url: RwLock::new((*self.source_map_url.read()).clone()),
|
||||
source_url: RwLock::new((*self.source_url.read()).clone()),
|
||||
use_counters: self.use_counters.clone(),
|
||||
_forbid_construction: (),
|
||||
}
|
||||
}
|
||||
@@ -405,7 +410,7 @@ impl Stylesheet {
|
||||
error_reporter: Option<&dyn ParseErrorReporter>,
|
||||
allow_import_rules: AllowImportRules,
|
||||
) {
|
||||
// FIXME: Consider adding use counters to Servo?
|
||||
let use_counters = UseCounters::default();
|
||||
let (namespaces, rules, source_map_url, source_url) = Self::parse_rules(
|
||||
css,
|
||||
&url_data,
|
||||
@@ -414,7 +419,7 @@ impl Stylesheet {
|
||||
stylesheet_loader,
|
||||
error_reporter,
|
||||
existing.contents.quirks_mode,
|
||||
/* use_counters = */ None,
|
||||
Some(&use_counters),
|
||||
allow_import_rules,
|
||||
/* sanitization_data = */ None,
|
||||
);
|
||||
@@ -427,6 +432,7 @@ impl Stylesheet {
|
||||
*existing.contents.rules.write_with(&mut guard) = CssRules(rules);
|
||||
*existing.contents.source_map_url.write() = source_map_url;
|
||||
*existing.contents.source_url.write() = source_url;
|
||||
existing.contents.use_counters.merge(&use_counters);
|
||||
}
|
||||
|
||||
fn parse_rules(
|
||||
@@ -531,7 +537,6 @@ impl Stylesheet {
|
||||
stylesheet_loader,
|
||||
error_reporter,
|
||||
quirks_mode,
|
||||
/* use_counters = */ None,
|
||||
allow_import_rules,
|
||||
/* sanitized_output = */ None,
|
||||
);
|
||||
|
||||
@@ -14,14 +14,14 @@ const BITS_PER_ENTRY: usize = 64;
|
||||
const BITS_PER_ENTRY: usize = 32;
|
||||
|
||||
/// One bit per each non-custom CSS property.
|
||||
#[derive(Default)]
|
||||
#[derive(Debug, Default, Clone)]
|
||||
pub struct CountedUnknownPropertyUseCounters {
|
||||
storage:
|
||||
[Cell<usize>; (property_counts::COUNTED_UNKNOWN - 1 + BITS_PER_ENTRY) / BITS_PER_ENTRY],
|
||||
}
|
||||
|
||||
/// One bit per each non-custom CSS property.
|
||||
#[derive(Default)]
|
||||
#[derive(Debug, Default, Clone)]
|
||||
pub struct NonCustomPropertyUseCounters {
|
||||
storage: [Cell<usize>; (property_counts::NON_CUSTOM - 1 + BITS_PER_ENTRY) / BITS_PER_ENTRY],
|
||||
}
|
||||
@@ -73,7 +73,7 @@ impl NonCustomPropertyUseCounters {
|
||||
}
|
||||
|
||||
/// The use-counter data related to a given document we want to store.
|
||||
#[derive(Default)]
|
||||
#[derive(Debug, Default, Clone)]
|
||||
pub struct UseCounters {
|
||||
/// The counters for non-custom properties that have been parsed in the
|
||||
/// document's stylesheets.
|
||||
|
||||
Reference in New Issue
Block a user