mirror of
https://github.com/servo/servo.git
synced 2025-08-04 13:10:20 +01:00
Introduce LayoutDom::to_layout_slice
It generalises <LayoutDom<Element>>::attrs.
This commit is contained in:
parent
72c0771299
commit
dd750c6f86
2 changed files with 10 additions and 8 deletions
|
@ -736,6 +736,15 @@ where
|
||||||
debug_assert!(thread_state::get().is_layout());
|
debug_assert!(thread_state::get().is_layout());
|
||||||
self.value
|
self.value
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Transforms a slice of Dom<T> into a slice of LayoutDom<T>.
|
||||||
|
// FIXME(nox): This should probably be done through a ToLayout trait.
|
||||||
|
pub unsafe fn to_layout_slice(slice: &'dom [Dom<T>]) -> &'dom [LayoutDom<'dom, T>] {
|
||||||
|
// This doesn't compile if Dom and LayoutDom don't have the same
|
||||||
|
// representation.
|
||||||
|
let _ = mem::transmute::<Dom<T>, LayoutDom<T>>;
|
||||||
|
&*(slice as *const [Dom<T>] as *const [LayoutDom<T>])
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Helper trait for safer manipulations of `Option<Heap<T>>` values.
|
/// Helper trait for safer manipulations of `Option<Heap<T>>` values.
|
||||||
|
|
|
@ -598,14 +598,7 @@ impl<'dom> LayoutElementHelpers<'dom> for LayoutDom<'dom, Element> {
|
||||||
#[allow(unsafe_code)]
|
#[allow(unsafe_code)]
|
||||||
#[inline]
|
#[inline]
|
||||||
fn attrs(self) -> &'dom [LayoutDom<'dom, Attr>] {
|
fn attrs(self) -> &'dom [LayoutDom<'dom, Attr>] {
|
||||||
unsafe {
|
unsafe { LayoutDom::to_layout_slice(self.unsafe_get().attrs.borrow_for_layout()) }
|
||||||
// FIXME(nox): This should probably be done through a ToLayout trait.
|
|
||||||
let attrs: &[Dom<Attr>] = &self.unsafe_get().attrs.borrow_for_layout();
|
|
||||||
// This doesn't compile if Dom and LayoutDom don't have the same
|
|
||||||
// representation.
|
|
||||||
let _ = mem::transmute::<Dom<Attr>, LayoutDom<Attr>>;
|
|
||||||
&*(attrs as *const [Dom<Attr>] as *const [LayoutDom<Attr>])
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue