diff options
author | Anthony Ramine <nox@nox.paris> | 2020-04-03 18:54:11 +0200 |
---|---|---|
committer | Anthony Ramine <nox@nox.paris> | 2020-04-04 13:10:19 +0200 |
commit | 185a402d9cc41d3e680b99564f5fc8b519ecf129 (patch) | |
tree | 14869f8e2feae209fcf75026fb079021986c13f9 /components/script_layout_interface/lib.rs | |
parent | 516e8e0aa600cdef34e506e0ed7180d12dd9ac7d (diff) | |
download | servo-185a402d9cc41d3e680b99564f5fc8b519ecf129.tar.gz servo-185a402d9cc41d3e680b99564f5fc8b519ecf129.zip |
Make DOM own the style and layout data, in an UnsafeCell
The previous Cell was a lie.
Diffstat (limited to 'components/script_layout_interface/lib.rs')
-rw-r--r-- | components/script_layout_interface/lib.rs | 20 |
1 files changed, 6 insertions, 14 deletions
diff --git a/components/script_layout_interface/lib.rs b/components/script_layout_interface/lib.rs index 6bfe0af2b30..6fb859aa112 100644 --- a/components/script_layout_interface/lib.rs +++ b/components/script_layout_interface/lib.rs @@ -26,7 +26,6 @@ use net_traits::image_cache::PendingImageId; use script_traits::UntrustedNodeAddress; use servo_url::{ImmutableOrigin, ServoUrl}; use std::any::Any; -use std::ptr::NonNull; use std::sync::atomic::AtomicIsize; use style::data::ElementData; @@ -51,12 +50,11 @@ impl StyleData { } } -#[derive(Clone, Copy, MallocSizeOf)] +#[derive(MallocSizeOf)] pub struct OpaqueStyleAndLayoutData { // NB: We really store a `StyleAndLayoutData` here, so be careful! - #[ignore_malloc_size_of = "TODO(#6910) Box value that should be counted but \ - the type lives in layout"] - ptr: NonNull<dyn Any + Send + Sync>, + #[ignore_malloc_size_of = "Trait objects are hard"] + ptr: Box<dyn Any + Send + Sync>, } impl OpaqueStyleAndLayoutData { @@ -66,23 +64,17 @@ impl OpaqueStyleAndLayoutData { T: Any + Send + Sync, { Self { - ptr: Box::into_raw_non_null(Box::new(value) as Box<dyn Any + Send + Sync>), + ptr: Box::new(value) as Box<dyn Any + Send + Sync>, } } - #[inline] - pub fn as_ptr(&self) -> *mut (dyn Any + Send + Sync) { - self.ptr.as_ptr() - } - /// Extremely cursed. - #[allow(unsafe_code)] #[inline] - pub unsafe fn downcast_ref<'extended, T>(&self) -> Option<&'extended T> + pub fn downcast_ref<T>(&self) -> Option<&T> where T: Any + Send + Sync, { - (*self.ptr.as_ptr()).downcast_ref() + self.ptr.downcast_ref() } } |