Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
style: Add ToShmem impl for UrlExtraData.
  • Loading branch information
heycam authored and emilio committed Apr 12, 2019
1 parent 41f6e67 commit 1f96653
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion components/style/stylesheets/mod.rs
Expand Up @@ -37,8 +37,9 @@ use malloc_size_of::{MallocSizeOfOps, MallocUnconditionalShallowSizeOf};
use servo_arc::Arc;
use std::fmt;
#[cfg(feature = "gecko")]
use std::mem;
use std::mem::{self, ManuallyDrop};
use style_traits::ParsingMode;
use to_shmem::{SharedMemoryBuilder, ToShmem};

pub use self::counter_style_rule::CounterStyleRule;
pub use self::document_rule::DocumentRule;
Expand Down Expand Up @@ -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")]
impl UrlExtraData {
/// Create a new UrlExtraData wrapping a pointer to the specified Gecko
Expand Down

0 comments on commit 1f96653

Please sign in to comment.