mirror of
https://github.com/servo/servo.git
synced 2025-08-09 07:25:35 +01:00
style: Use fallible allocation for stylesheet invalidation.
If the sets get too big we cannot allocate anything else, we'll just empty them and invalidate the whole document. Differential Revision: https://phabricator.services.mozilla.com/D46828
This commit is contained in:
parent
c349dbbaa9
commit
3cb18071a2
2 changed files with 27 additions and 10 deletions
|
@ -17,6 +17,8 @@ use std::ops::{BitAnd, BitOr, BitXor, Sub};
|
||||||
use super::hash_map::{self, HashMap, Keys, RandomState};
|
use super::hash_map::{self, HashMap, Keys, RandomState};
|
||||||
use super::Recover;
|
use super::Recover;
|
||||||
|
|
||||||
|
use crate::FailedAllocationError;
|
||||||
|
|
||||||
// Future Optimization (FIXME!)
|
// Future Optimization (FIXME!)
|
||||||
// =============================
|
// =============================
|
||||||
//
|
//
|
||||||
|
@ -589,6 +591,12 @@ where
|
||||||
self.map.insert(value, ()).is_none()
|
self.map.insert(value, ()).is_none()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Fallible version of `insert`.
|
||||||
|
#[inline]
|
||||||
|
pub fn try_insert(&mut self, value: T) -> Result<bool, FailedAllocationError> {
|
||||||
|
Ok(self.map.try_insert(value, ())?.is_none())
|
||||||
|
}
|
||||||
|
|
||||||
/// Adds a value to the set, replacing the existing value, if any, that is equal to the given
|
/// Adds a value to the set, replacing the existing value, if any, that is equal to the given
|
||||||
/// one. Returns the replaced value.
|
/// one. Returns the replaced value.
|
||||||
pub fn replace(&mut self, value: T) -> Option<T> {
|
pub fn replace(&mut self, value: T) -> Option<T> {
|
||||||
|
|
|
@ -8,6 +8,7 @@
|
||||||
#![deny(unsafe_code)]
|
#![deny(unsafe_code)]
|
||||||
|
|
||||||
use crate::dom::{TDocument, TElement, TNode};
|
use crate::dom::{TDocument, TElement, TNode};
|
||||||
|
use crate::hash::HashSet;
|
||||||
use crate::invalidation::element::element_wrapper::{ElementSnapshot, ElementWrapper};
|
use crate::invalidation::element::element_wrapper::{ElementSnapshot, ElementWrapper};
|
||||||
use crate::invalidation::element::restyle_hints::RestyleHint;
|
use crate::invalidation::element::restyle_hints::RestyleHint;
|
||||||
use crate::media_queries::Device;
|
use crate::media_queries::Device;
|
||||||
|
@ -17,9 +18,12 @@ use crate::stylesheets::{CssRule, StylesheetInDocument};
|
||||||
use crate::Atom;
|
use crate::Atom;
|
||||||
use crate::CaseSensitivityExt;
|
use crate::CaseSensitivityExt;
|
||||||
use crate::LocalName as SelectorLocalName;
|
use crate::LocalName as SelectorLocalName;
|
||||||
use fxhash::FxHashSet;
|
use fxhash::FxHasher;
|
||||||
use selectors::attr::CaseSensitivity;
|
use selectors::attr::CaseSensitivity;
|
||||||
use selectors::parser::{Component, LocalName, Selector};
|
use selectors::parser::{Component, LocalName, Selector};
|
||||||
|
use std::hash::BuildHasherDefault;
|
||||||
|
|
||||||
|
type FxHashSet<K> = HashSet<K, BuildHasherDefault<FxHasher>>;
|
||||||
|
|
||||||
/// A style sheet invalidation represents a kind of element or subtree that may
|
/// A style sheet invalidation represents a kind of element or subtree that may
|
||||||
/// need to be restyled. Whether it represents a whole subtree or just a single
|
/// need to be restyled. Whether it represents a whole subtree or just a single
|
||||||
|
@ -400,16 +404,21 @@ impl StylesheetInvalidationSet {
|
||||||
|
|
||||||
if let Some(s) = subtree_invalidation {
|
if let Some(s) = subtree_invalidation {
|
||||||
debug!(" > Found subtree invalidation: {:?}", s);
|
debug!(" > Found subtree invalidation: {:?}", s);
|
||||||
self.invalid_scopes.insert(s);
|
if self.invalid_scopes.try_insert(s).is_ok() {
|
||||||
} else if let Some(s) = element_invalidation {
|
return;
|
||||||
debug!(" > Found element invalidation: {:?}", s);
|
}
|
||||||
self.invalid_elements.insert(s);
|
|
||||||
} else {
|
|
||||||
// The selector was of a form that we can't handle. Any element
|
|
||||||
// could match it, so let's just bail out.
|
|
||||||
debug!(" > Can't handle selector, marking fully invalid");
|
|
||||||
self.fully_invalid = true;
|
|
||||||
}
|
}
|
||||||
|
if let Some(s) = element_invalidation {
|
||||||
|
debug!(" > Found element invalidation: {:?}", s);
|
||||||
|
if self.invalid_elements.try_insert(s).is_ok() {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// The selector was of a form that we can't handle. Any element could
|
||||||
|
// match it, so let's just bail out.
|
||||||
|
debug!(" > Can't handle selector or OOMd, marking fully invalid");
|
||||||
|
self.fully_invalid = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Collects invalidations for a given CSS rule.
|
/// Collects invalidations for a given CSS rule.
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue