stylo: Stop cloning the list of stylesheets each flush.

This commit is contained in:
Emilio Cobos Álvarez 2017-05-11 01:53:59 +02:00
parent 677daaabc5
commit 25d39006b6
No known key found for this signature in database
GPG key ID: 056B727BB9C1027C
2 changed files with 18 additions and 9 deletions

View file

@ -18,7 +18,7 @@ use std::collections::HashMap;
use std::sync::mpsc::{Receiver, Sender, channel}; use std::sync::mpsc::{Receiver, Sender, channel};
use stylearc::Arc; use stylearc::Arc;
use stylesheet_set::StylesheetSet; use stylesheet_set::StylesheetSet;
use stylesheets::{FontFaceRule, Origin, Stylesheet}; use stylesheets::{FontFaceRule, Origin};
use stylist::{ExtraStyleData, Stylist}; use stylist::{ExtraStyleData, Stylist};
/// The container for data that a Servo-backed Gecko document needs to style /// The container for data that a Servo-backed Gecko document needs to style
@ -102,10 +102,8 @@ impl PerDocumentStyleDataImpl {
}; };
let author_style_disabled = self.stylesheets.author_style_disabled(); let author_style_disabled = self.stylesheets.author_style_disabled();
let mut stylesheets = Vec::<Arc<Stylesheet>>::new();
self.stylesheets.flush(&mut stylesheets);
self.stylist.clear(); self.stylist.clear();
self.stylist.rebuild(stylesheets.iter(), self.stylist.rebuild(self.stylesheets.flush(),
&StylesheetGuards::same(guard), &StylesheetGuards::same(guard),
/* ua_sheets = */ None, /* ua_sheets = */ None,
/* stylesheets_changed = */ true, /* stylesheets_changed = */ true,

View file

@ -4,6 +4,7 @@
//! A centralized set of stylesheets for a document. //! A centralized set of stylesheets for a document.
use std::slice;
use stylearc::Arc; use stylearc::Arc;
use stylesheets::Stylesheet; use stylesheets::Stylesheet;
@ -14,6 +15,17 @@ pub struct StylesheetSetEntry {
sheet: Arc<Stylesheet>, sheet: Arc<Stylesheet>,
} }
/// A iterator over the stylesheets of a list of entries in the StylesheetSet.
#[derive(Clone)]
pub struct StylesheetIterator<'a>(slice::Iter<'a, StylesheetSetEntry>);
impl<'a> Iterator for StylesheetIterator<'a> {
type Item = &'a Arc<Stylesheet>;
fn next(&mut self) -> Option<Self::Item> {
self.0.next().map(|entry| &entry.sheet)
}
}
/// The set of stylesheets effective for a given document. /// The set of stylesheets effective for a given document.
pub struct StylesheetSet { pub struct StylesheetSet {
/// The actual list of all the stylesheets that apply to the given document, /// The actual list of all the stylesheets that apply to the given document,
@ -108,12 +120,11 @@ impl StylesheetSet {
self.dirty self.dirty
} }
/// Flush the current set, unmarking it as dirty. /// Flush the current set, unmarking it as dirty, and returns an iterator
pub fn flush(&mut self, sheets: &mut Vec<Arc<Stylesheet>>) { /// over the new stylesheet list.
pub fn flush(&mut self) -> StylesheetIterator {
self.dirty = false; self.dirty = false;
for entry in &self.entries { StylesheetIterator(self.entries.iter())
sheets.push(entry.sheet.clone())
}
} }
/// Mark the stylesheets as dirty, because something external may have /// Mark the stylesheets as dirty, because something external may have