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:
Emilio Cobos Álvarez 2019-09-23 19:08:22 +00:00
parent c349dbbaa9
commit 3cb18071a2
2 changed files with 27 additions and 10 deletions

View file

@ -17,6 +17,8 @@ use std::ops::{BitAnd, BitOr, BitXor, Sub};
use super::hash_map::{self, HashMap, Keys, RandomState};
use super::Recover;
use crate::FailedAllocationError;
// Future Optimization (FIXME!)
// =============================
//
@ -589,6 +591,12 @@ where
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
/// one. Returns the replaced value.
pub fn replace(&mut self, value: T) -> Option<T> {