aboutsummaryrefslogtreecommitdiffstats
path: root/components
diff options
context:
space:
mode:
authorEmilio Cobos Álvarez <emilio@crisal.io>2017-05-11 01:53:59 +0200
committerEmilio Cobos Álvarez <emilio@crisal.io>2017-05-12 14:51:01 +0200
commit25d39006b66a2d761d2ea9affb265be31822ca9d (patch)
tree4072025565cded515bd4d55c807421d2fdc945b5 /components
parent677daaabc54a4ea88195640058b5781d0037cb5b (diff)
downloadservo-25d39006b66a2d761d2ea9affb265be31822ca9d.tar.gz
servo-25d39006b66a2d761d2ea9affb265be31822ca9d.zip
stylo: Stop cloning the list of stylesheets each flush.
Diffstat (limited to 'components')
-rw-r--r--components/style/gecko/data.rs6
-rw-r--r--components/style/stylesheet_set.rs21
2 files changed, 18 insertions, 9 deletions
diff --git a/components/style/gecko/data.rs b/components/style/gecko/data.rs
index d51b1795bce..d8397ddeb93 100644
--- a/components/style/gecko/data.rs
+++ b/components/style/gecko/data.rs
@@ -18,7 +18,7 @@ use std::collections::HashMap;
use std::sync::mpsc::{Receiver, Sender, channel};
use stylearc::Arc;
use stylesheet_set::StylesheetSet;
-use stylesheets::{FontFaceRule, Origin, Stylesheet};
+use stylesheets::{FontFaceRule, Origin};
use stylist::{ExtraStyleData, Stylist};
/// 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 mut stylesheets = Vec::<Arc<Stylesheet>>::new();
- self.stylesheets.flush(&mut stylesheets);
self.stylist.clear();
- self.stylist.rebuild(stylesheets.iter(),
+ self.stylist.rebuild(self.stylesheets.flush(),
&StylesheetGuards::same(guard),
/* ua_sheets = */ None,
/* stylesheets_changed = */ true,
diff --git a/components/style/stylesheet_set.rs b/components/style/stylesheet_set.rs
index 0cc6f4fbf51..da4e75e5eca 100644
--- a/components/style/stylesheet_set.rs
+++ b/components/style/stylesheet_set.rs
@@ -4,6 +4,7 @@
//! A centralized set of stylesheets for a document.
+use std::slice;
use stylearc::Arc;
use stylesheets::Stylesheet;
@@ -14,6 +15,17 @@ pub struct StylesheetSetEntry {
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.
pub struct StylesheetSet {
/// The actual list of all the stylesheets that apply to the given document,
@@ -108,12 +120,11 @@ impl StylesheetSet {
self.dirty
}
- /// Flush the current set, unmarking it as dirty.
- pub fn flush(&mut self, sheets: &mut Vec<Arc<Stylesheet>>) {
+ /// Flush the current set, unmarking it as dirty, and returns an iterator
+ /// over the new stylesheet list.
+ pub fn flush(&mut self) -> StylesheetIterator {
self.dirty = false;
- for entry in &self.entries {
- sheets.push(entry.sheet.clone())
- }
+ StylesheetIterator(self.entries.iter())
}
/// Mark the stylesheets as dirty, because something external may have