Tweak list of shadow roots attached to doc

This commit is contained in:
Fernando Jiménez Moreno 2019-03-06 18:02:10 +01:00
parent b8925a0297
commit 0313e38074
3 changed files with 14 additions and 10 deletions

View file

@ -377,7 +377,7 @@ pub struct Document {
/// https://html.spec.whatwg.org/multipage/#completely-loaded
completely_loaded: Cell<bool>,
/// List of shadow roots bound to the document tree.
shadow_roots: DomRefCell<Vec<Dom<ShadowRoot>>>,
shadow_roots: DomRefCell<HashSet<Dom<ShadowRoot>>>,
/// Whether any of the shadow roots need the stylesheets flushed.
shadow_roots_styles_changed: Cell<bool>,
}
@ -2674,7 +2674,7 @@ impl Document {
completely_loaded: Cell::new(false),
script_and_layout_blockers: Cell::new(0),
delayed_tasks: Default::default(),
shadow_roots: DomRefCell::new(Vec::new()),
shadow_roots: DomRefCell::new(HashSet::new()),
shadow_roots_styles_changed: Cell::new(false),
}
}
@ -3132,16 +3132,13 @@ impl Document {
pub fn register_shadow_root(&self, shadow_root: &ShadowRoot) {
self.shadow_roots
.borrow_mut()
.push(Dom::from_ref(shadow_root));
.insert(Dom::from_ref(shadow_root));
self.invalidate_shadow_roots_stylesheets();
}
pub fn unregister_shadow_root(&self, shadow_root: &ShadowRoot) {
let mut shadow_roots = self.shadow_roots.borrow_mut();
let position = shadow_roots.iter().position(|sr| **sr == *shadow_root);
if let Some(index) = position {
shadow_roots.remove(index);
}
shadow_roots.remove(&Dom::from_ref(shadow_root));
}
pub fn invalidate_shadow_roots_stylesheets(&self) {