Bug 1474793 - Part 10.6: Add ToShmem impl for UrlExtraData. r=emilio
authorCameron McCormack <cam@mcc.id.au>
Sat, 30 Mar 2019 00:16:21 +0000
changeset 466904 6fe8bc63321513f16bdfa2df653dc940cde8035e
parent 466903 cc47e694718e9b6a23412e76f91b209dbd9b2dd7
child 466905 637160560b12e63b745bed56bae1c197a0326425
push id112603
push usernerli@mozilla.com
push dateSat, 30 Mar 2019 09:35:57 +0000
treeherdermozilla-inbound@7c3183c56eb6 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersemilio
bugs1474793
milestone68.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1474793 - Part 10.6: Add ToShmem impl for UrlExtraData. r=emilio Depends on D17194 Differential Revision: https://phabricator.services.mozilla.com/D17195
servo/components/style/stylesheets/mod.rs
--- a/servo/components/style/stylesheets/mod.rs
+++ b/servo/components/style/stylesheets/mod.rs
@@ -32,18 +32,19 @@ use crate::shared_lock::{DeepCloneParams
 use crate::shared_lock::{SharedRwLock, SharedRwLockReadGuard, ToCssWithGuard};
 use crate::str::CssStringWriter;
 use cssparser::{parse_one_rule, Parser, ParserInput};
 #[cfg(feature = "gecko")]
 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;
 pub use self::font_face_rule::FontFaceRule;
 pub use self::font_feature_values_rule::FontFeatureValuesRule;
 pub use self::import_rule::ImportRule;
 pub use self::keyframes_rule::KeyframesRule;
 pub use self::loader::StylesheetLoader;
@@ -97,16 +98,36 @@ impl Drop for UrlExtraData {
             unsafe {
                 self.as_ref().release();
             }
         }
     }
 }
 
 #[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
     /// URLExtraData object.
     pub fn new(ptr: *mut structs::URLExtraData) -> UrlExtraData {
         unsafe {
             (*ptr).addref();
         }
         UrlExtraData(ptr as usize)