style: Parameterize the update and rebuild methods to take an iterator.

In preparation to avoid cloning the stylesheets while rebuilding in Gecko.
This commit is contained in:
Emilio Cobos Álvarez 2017-05-11 01:45:00 +02:00
parent 50e0c67e2c
commit 677daaabc5
No known key found for this signature in database
GPG key ID: 056B727BB9C1027C
5 changed files with 39 additions and 30 deletions

View file

@ -268,13 +268,15 @@ impl Stylist {
/// This method resets all the style data each time the stylesheets change
/// (which is indicated by the `stylesheets_changed` parameter), or the
/// device is dirty, which means we need to re-evaluate media queries.
pub fn rebuild<'a>(&mut self,
doc_stylesheets: &[Arc<Stylesheet>],
guards: &StylesheetGuards,
ua_stylesheets: Option<&UserAgentStylesheets>,
stylesheets_changed: bool,
author_style_disabled: bool,
extra_data: &mut ExtraStyleData<'a>) -> bool {
pub fn rebuild<'a, 'b, I>(&mut self,
doc_stylesheets: I,
guards: &StylesheetGuards,
ua_stylesheets: Option<&UserAgentStylesheets>,
stylesheets_changed: bool,
author_style_disabled: bool,
extra_data: &mut ExtraStyleData<'a>) -> bool
where I: Iterator<Item = &'b Arc<Stylesheet>> + Clone,
{
debug_assert!(!self.is_cleared || self.is_device_dirty);
self.is_cleared = false;
@ -287,7 +289,7 @@ impl Stylist {
let cascaded_rule = ViewportRule {
declarations: viewport::Cascade::from_stylesheets(
doc_stylesheets, guards.author, &self.device
doc_stylesheets.clone(), guards.author, &self.device
).finish(),
};
@ -317,7 +319,7 @@ impl Stylist {
}
// Only use author stylesheets if author styles are enabled.
let sheets_to_add = doc_stylesheets.iter().filter(|s| {
let sheets_to_add = doc_stylesheets.filter(|s| {
!author_style_disabled || s.origin != Origin::Author
});
@ -338,13 +340,15 @@ impl Stylist {
/// clear the stylist and then rebuild it. Chances are, you want to use
/// either clear() or rebuild(), with the latter done lazily, instead.
pub fn update<'a>(&mut self,
doc_stylesheets: &[Arc<Stylesheet>],
guards: &StylesheetGuards,
ua_stylesheets: Option<&UserAgentStylesheets>,
stylesheets_changed: bool,
author_style_disabled: bool,
extra_data: &mut ExtraStyleData<'a>) -> bool {
pub fn update<'a, 'b, I>(&mut self,
doc_stylesheets: I,
guards: &StylesheetGuards,
ua_stylesheets: Option<&UserAgentStylesheets>,
stylesheets_changed: bool,
author_style_disabled: bool,
extra_data: &mut ExtraStyleData<'a>) -> bool
where I: Iterator<Item = &'b Arc<Stylesheet>> + Clone,
{
debug_assert!(!self.is_cleared || self.is_device_dirty);
// We have to do a dirtiness check before clearing, because if
@ -357,7 +361,9 @@ impl Stylist {
author_style_disabled, extra_data)
}
fn add_stylesheet<'a>(&mut self, stylesheet: &Stylesheet, guard: &SharedRwLockReadGuard,
fn add_stylesheet<'a>(&mut self,
stylesheet: &Stylesheet,
guard: &SharedRwLockReadGuard,
extra_data: &mut ExtraStyleData<'a>) {
if stylesheet.disabled() || !stylesheet.is_effective_for_device(&self.device, guard) {
return;
@ -656,10 +662,12 @@ impl Stylist {
/// FIXME(emilio): The semantics of the device for Servo and Gecko are
/// different enough we may want to unify them.
#[cfg(feature = "servo")]
pub fn set_device(&mut self, mut device: Device, guard: &SharedRwLockReadGuard,
pub fn set_device(&mut self,
mut device: Device,
guard: &SharedRwLockReadGuard,
stylesheets: &[Arc<Stylesheet>]) {
let cascaded_rule = ViewportRule {
declarations: viewport::Cascade::from_stylesheets(stylesheets, guard, &device).finish(),
declarations: viewport::Cascade::from_stylesheets(stylesheets.iter(), guard, &device).finish(),
};
self.viewport_constraints =