Make DOMRefCell use style’s copy of RefCell

This commit is contained in:
Simon Sapin 2016-08-30 22:17:24 +02:00
parent edbd88cce5
commit ec723057b2
12 changed files with 31 additions and 24 deletions

View file

@ -15,6 +15,7 @@
#![allow(unsafe_code)]
#[cfg(feature = "servo")] use heapsize::HeapSizeOf;
use std::cell::{UnsafeCell, Cell};
use std::cmp::Ordering;
use std::fmt::{self, Debug, Display};
@ -31,6 +32,13 @@ pub struct RefCell<T: ?Sized> {
value: UnsafeCell<T>,
}
#[cfg(feature = "servo")]
impl<T: HeapSizeOf> HeapSizeOf for RefCell<T> {
fn heap_size_of_children(&self) -> usize {
self.borrow().heap_size_of_children()
}
}
/// An enumeration of values returned from the `state` method on a `RefCell<T>`.
#[derive(Copy, Clone, PartialEq, Eq, Debug)]
pub enum BorrowState {
@ -527,6 +535,18 @@ impl<'b, T: ?Sized> Ref<'b, T> {
borrow: orig.borrow,
}
}
#[inline]
pub fn filter_map<U: ?Sized, F>(orig: Ref<'b, T>, f: F) -> Option<Ref<'b, U>>
where F: FnOnce(&T) -> Option<&U>
{
f(orig.value).map(move |new_value| {
Ref {
value: new_value,
borrow: orig.borrow,
}
})
}
}
impl<'b, T: ?Sized> RefMut<'b, T> {