style: Add ToShmem impl for UrlExtraData.

Differential Revision: https://phabricator.services.mozilla.com/D17195
This commit is contained in:
Cameron McCormack 2019-03-30 00:16:21 +00:00 committed by Emilio Cobos Álvarez
parent 41f6e67893
commit 1f966535ac

View file

@ -37,8 +37,9 @@ use malloc_size_of::{MallocSizeOfOps, MallocUnconditionalShallowSizeOf};
use servo_arc::Arc; use servo_arc::Arc;
use std::fmt; use std::fmt;
#[cfg(feature = "gecko")] #[cfg(feature = "gecko")]
use std::mem; use std::mem::{self, ManuallyDrop};
use style_traits::ParsingMode; use style_traits::ParsingMode;
use to_shmem::{SharedMemoryBuilder, ToShmem};
pub use self::counter_style_rule::CounterStyleRule; pub use self::counter_style_rule::CounterStyleRule;
pub use self::document_rule::DocumentRule; pub use self::document_rule::DocumentRule;
@ -101,6 +102,26 @@ impl Drop for UrlExtraData {
} }
} }
#[cfg(feature = "gecko")]
impl ToShmem for UrlExtraData {
fn to_shmem(&self, _builder: &mut SharedMemoryBuilder) -> ManuallyDrop<Self> {
if self.0 & 1 == 0 {
let shared_extra_datas = unsafe { &structs::URLExtraData_sShared };
let self_ptr = self.as_ref() as *const _ as *mut _;
let sheet_id = shared_extra_datas
.iter()
.position(|r| r.mRawPtr == self_ptr)
.expect(
"ToShmem failed for UrlExtraData: expected sheet's URLExtraData to be in \
URLExtraData::sShared",
);
ManuallyDrop::new(UrlExtraData((sheet_id << 1) | 1))
} else {
ManuallyDrop::new(UrlExtraData(self.0))
}
}
}
#[cfg(feature = "gecko")] #[cfg(feature = "gecko")]
impl UrlExtraData { impl UrlExtraData {
/// Create a new UrlExtraData wrapping a pointer to the specified Gecko /// Create a new UrlExtraData wrapping a pointer to the specified Gecko