diff options
author | Simon Sapin <simon.sapin@exyr.org> | 2017-10-12 02:00:33 +0200 |
---|---|---|
committer | Simon Sapin <simon.sapin@exyr.org> | 2017-10-13 11:11:02 +0200 |
commit | 7ebedd02a9b8da03c9b5d5d8ff876beeedeb7ecf (patch) | |
tree | 64740d252d20c7b6e4add4433171776fca4e577b | |
parent | ff23a8536e53fda502dc17f8e9b3d32554ed1264 (diff) | |
download | servo-7ebedd02a9b8da03c9b5d5d8ff876beeedeb7ecf.tar.gz servo-7ebedd02a9b8da03c9b5d5d8ff876beeedeb7ecf.zip |
Use NonZeroUsize in script_layout_interface
-rw-r--r-- | Cargo.lock | 2 | ||||
-rw-r--r-- | components/layout_thread/Cargo.toml | 3 | ||||
-rw-r--r-- | components/layout_thread/dom_wrapper.rs | 11 | ||||
-rw-r--r-- | components/layout_thread/lib.rs | 4 | ||||
-rw-r--r-- | components/nonzero/lib.rs | 16 | ||||
-rw-r--r-- | components/script_layout_interface/Cargo.toml | 4 | ||||
-rw-r--r-- | components/script_layout_interface/lib.rs | 10 | ||||
-rw-r--r-- | components/servo/Cargo.toml | 1 |
8 files changed, 38 insertions, 13 deletions
diff --git a/Cargo.lock b/Cargo.lock index 998660b30ae..3f2ad59e575 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1567,6 +1567,7 @@ dependencies = [ "metrics 0.0.1", "msg 0.0.1", "net_traits 0.0.1", + "nonzero 0.0.1", "parking_lot 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", "profile_traits 0.0.1", "range 0.0.1", @@ -2675,6 +2676,7 @@ dependencies = [ "metrics 0.0.1", "msg 0.0.1", "net_traits 0.0.1", + "nonzero 0.0.1", "profile_traits 0.0.1", "range 0.0.1", "script_traits 0.0.1", diff --git a/components/layout_thread/Cargo.toml b/components/layout_thread/Cargo.toml index eea55c032df..5bb340f893a 100644 --- a/components/layout_thread/Cargo.toml +++ b/components/layout_thread/Cargo.toml @@ -10,7 +10,7 @@ name = "layout_thread" path = "lib.rs" [features] -unstable = ["parking_lot/nightly"] +unstable = ["parking_lot/nightly", "nonzero/unstable"] [dependencies] app_units = "0.5" @@ -29,6 +29,7 @@ log = "0.3.5" metrics = {path = "../metrics"} msg = {path = "../msg"} net_traits = {path = "../net_traits"} +nonzero = {path = "../nonzero"} parking_lot = "0.4" profile_traits = {path = "../profile_traits"} range = {path = "../range"} diff --git a/components/layout_thread/dom_wrapper.rs b/components/layout_thread/dom_wrapper.rs index 525e1afb5f0..2a95324ccb7 100644 --- a/components/layout_thread/dom_wrapper.rs +++ b/components/layout_thread/dom_wrapper.rs @@ -31,12 +31,12 @@ #![allow(unsafe_code)] use atomic_refcell::{AtomicRef, AtomicRefMut, AtomicRefCell}; -use core::nonzero::NonZero; use gfx_traits::ByteIndex; use html5ever::{LocalName, Namespace}; use layout::data::StyleAndLayoutData; use layout::wrapper::GetRawData; use msg::constellation_msg::{BrowsingContextId, PipelineId}; +use nonzero::NonZeroUsize; use range::Range; use script::layout_exports::{CAN_BE_FRAGMENTED, HAS_DIRTY_DESCENDANTS, IS_IN_DOC}; use script::layout_exports::{CharacterDataTypeId, ElementTypeId, HTMLElementTypeId, NodeTypeId}; @@ -79,7 +79,7 @@ use style::shared_lock::{SharedRwLock as StyleSharedRwLock, Locked as StyleLocke use style::str::is_whitespace; pub unsafe fn drop_style_and_layout_data(data: OpaqueStyleAndLayoutData) { - let ptr: *mut StyleData = data.ptr.get(); + let ptr = data.ptr.get() as *mut StyleData; let non_opaque: *mut StyleAndLayoutData = ptr as *mut _; let _ = Box::from_raw(non_opaque); } @@ -235,7 +235,8 @@ impl<'ln> LayoutNode for ServoLayoutNode<'ln> { let ptr: *mut StyleAndLayoutData = Box::into_raw(Box::new(StyleAndLayoutData::new())); let opaque = OpaqueStyleAndLayoutData { - ptr: NonZero::new_unchecked(ptr as *mut StyleData), + ptr: NonZeroUsize::new_unchecked(ptr as usize), + phantom: PhantomData, }; self.init_style_and_layout_data(opaque); }; @@ -471,7 +472,7 @@ impl<'le> TElement for ServoLayoutElement<'le> { fn get_data(&self) -> Option<&AtomicRefCell<ElementData>> { unsafe { self.get_style_and_layout_data().map(|d| { - &(*d.ptr.get()).element_data + &(*(d.ptr.get() as *mut StyleData)).element_data }) } } @@ -583,7 +584,7 @@ impl<'le> ServoLayoutElement<'le> { fn get_style_data(&self) -> Option<&StyleData> { unsafe { - self.get_style_and_layout_data().map(|d| &*d.ptr.get()) + self.get_style_and_layout_data().map(|d| &*(d.ptr.get() as *mut StyleData)) } } diff --git a/components/layout_thread/lib.rs b/components/layout_thread/lib.rs index 8ea36ae100f..1fe552588bf 100644 --- a/components/layout_thread/lib.rs +++ b/components/layout_thread/lib.rs @@ -6,11 +6,10 @@ //! painted. #![feature(mpsc_select)] -#![feature(nonzero)] +#![cfg_attr(feature = "unstable", feature(nonzero))] extern crate app_units; extern crate atomic_refcell; -extern crate core; extern crate euclid; extern crate fnv; extern crate gfx; @@ -29,6 +28,7 @@ extern crate log; extern crate metrics; extern crate msg; extern crate net_traits; +extern crate nonzero; extern crate parking_lot; #[macro_use] extern crate profile_traits; diff --git a/components/nonzero/lib.rs b/components/nonzero/lib.rs index efc6eca2f0a..078bd0f5b2c 100644 --- a/components/nonzero/lib.rs +++ b/components/nonzero/lib.rs @@ -31,6 +31,7 @@ mod imp { pub struct NonZeroU32(u32); impl NonZeroU32 { + #[inline] pub fn new(x: u32) -> Option<Self> { if x != 0 { Some(NonZeroU32(x)) @@ -39,10 +40,12 @@ mod imp { } } + #[inline] pub unsafe fn new_unchecked(x: u32) -> Self { NonZeroU32(x) } + #[inline] pub fn get(self) -> u32 { self.0 } @@ -52,38 +55,49 @@ mod imp { pub struct NonZeroUsize(&'static ()); impl NonZeroUsize { + #[inline] pub fn new(x: usize) -> Option<Self> { if x != 0 { - Some(NonZeroUsize(unsafe { &*(x as *const ()) })) + Some(unsafe { Self::new_unchecked(x) }) } else { None } } + #[inline] + pub unsafe fn new_unchecked(x: usize) -> Self { + NonZeroUsize(&*(x as *const ())) + } + + #[inline] pub fn get(self) -> usize { self.0 as *const () as usize } } impl PartialEq for NonZeroUsize { + #[inline] fn eq(&self, other: &Self) -> bool { self.get() == other.get() } } impl PartialOrd for NonZeroUsize { + #[inline] fn partial_cmp(&self, other: &Self) -> Option<cmp::Ordering> { self.get().partial_cmp(&other.get()) } } impl Ord for NonZeroUsize { + #[inline] fn cmp(&self, other: &Self) -> cmp::Ordering { self.get().cmp(&other.get()) } } impl hash::Hash for NonZeroUsize { + #[inline] fn hash<H: hash::Hasher>(&self, hasher: &mut H) { self.get().hash(hasher) } diff --git a/components/script_layout_interface/Cargo.toml b/components/script_layout_interface/Cargo.toml index 0928de56156..acdea4bca17 100644 --- a/components/script_layout_interface/Cargo.toml +++ b/components/script_layout_interface/Cargo.toml @@ -9,6 +9,9 @@ publish = false name = "script_layout_interface" path = "lib.rs" +[features] +unstable = ["nonzero/unstable"] + [dependencies] app_units = "0.5" atomic_refcell = "0.1" @@ -25,6 +28,7 @@ log = "0.3.5" metrics = {path = "../metrics"} msg = {path = "../msg"} net_traits = {path = "../net_traits"} +nonzero = {path = "../nonzero"} profile_traits = {path = "../profile_traits"} range = {path = "../range"} script_traits = {path = "../script_traits"} diff --git a/components/script_layout_interface/lib.rs b/components/script_layout_interface/lib.rs index ffc41351ee5..f81092a8492 100644 --- a/components/script_layout_interface/lib.rs +++ b/components/script_layout_interface/lib.rs @@ -7,12 +7,11 @@ //! to depend on script. #![deny(unsafe_code)] -#![feature(nonzero)] +#![cfg_attr(feature = "unstable", feature(nonzero))] extern crate app_units; extern crate atomic_refcell; extern crate canvas_traits; -extern crate core; extern crate cssparser; extern crate euclid; extern crate gfx_traits; @@ -26,6 +25,7 @@ extern crate log; extern crate metrics; extern crate msg; extern crate net_traits; +extern crate nonzero; extern crate profile_traits; extern crate range; extern crate script_traits; @@ -43,12 +43,13 @@ pub mod wrapper_traits; use atomic_refcell::AtomicRefCell; use canvas_traits::canvas::CanvasMsg; -use core::nonzero::NonZero; use ipc_channel::ipc::IpcSender; use libc::c_void; use net_traits::image_cache::PendingImageId; +use nonzero::NonZeroUsize; use script_traits::UntrustedNodeAddress; use servo_url::ServoUrl; +use std::marker::PhantomData; use std::sync::atomic::AtomicIsize; use style::data::ElementData; @@ -78,7 +79,8 @@ pub struct OpaqueStyleAndLayoutData { // NB: We really store a `StyleAndLayoutData` here, so be careful! #[ignore_heap_size_of = "TODO(#6910) Box value that should be counted but \ the type lives in layout"] - pub ptr: NonZero<*mut StyleData> + pub ptr: NonZeroUsize, + pub phantom: PhantomData<*mut StyleData>, } #[allow(unsafe_code)] diff --git a/components/servo/Cargo.toml b/components/servo/Cargo.toml index 18837d14078..4858ef1b3f3 100644 --- a/components/servo/Cargo.toml +++ b/components/servo/Cargo.toml @@ -27,6 +27,7 @@ unstable = [ "constellation/unstable", "gfx/unstable", "profile/unstable", + "script_layout_interface/unstable", ] [dependencies] |