mirror of
https://github.com/servo/servo.git
synced 2025-07-23 07:13:52 +01:00
stylo: Stop cloning the list of stylesheets each flush.
This commit is contained in:
parent
677daaabc5
commit
25d39006b6
2 changed files with 18 additions and 9 deletions
|
@ -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,
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue