servo: Merge #11394 - Reduce the size of StackingContextId (from mbrubeck:stacking-context-id); r=pcwalton
authorMatt Brubeck <mbrubeck@limpet.net>
Thu, 26 May 2016 07:25:58 -0500
changeset 338926 625bf52d5225882666ede6918a97d43f42319844
parent 338925 fd119bfd4abfe2fc2f7dfed6201315d73f7e09d4
child 338927 8db013e426faa48fc6c4859225c31a7200434b7d
push id31307
push usergszorc@mozilla.com
push dateSat, 04 Feb 2017 00:59:06 +0000
treeherdermozilla-central@94079d43835f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerspcwalton
servo: Merge #11394 - Reduce the size of StackingContextId (from mbrubeck:stacking-context-id); r=pcwalton r? @pcwalton Source-Repo: https://github.com/servo/servo Source-Revision: 2acb257a82601ad9b48a544cff20ce83f6311a47
servo/components/gfx/display_list/mod.rs
servo/tests/unit/layout/size_of.rs
--- a/servo/components/gfx/display_list/mod.rs
+++ b/servo/components/gfx/display_list/mod.rs
@@ -1404,30 +1404,31 @@ pub enum FragmentType {
     BeforePseudoContent,
     /// A StackingContext created to contain ::after pseudo-element content.
     AfterPseudoContent,
 }
 
 /// A unique ID for every stacking context.
 #[derive(Clone, Copy, Debug, Deserialize, Eq, Hash, HeapSizeOf, PartialEq, RustcEncodable, Serialize)]
 pub struct StackingContextId(
-    /// The type of the fragment for this StackingContext. This serves to differentiate
-    /// StackingContexts that share fragments.
-    FragmentType,
-    /// The identifier for this StackingContexts, derived from the Flow's memory address.
+    /// The identifier for this StackingContext, derived from the Flow's memory address
+    /// and fragment type.  As a space optimization, these are combined into a single word.
     usize
 );
 
 impl StackingContextId {
+    #[inline(always)]
     pub fn new(id: usize) -> StackingContextId {
-        StackingContextId(FragmentType::FragmentBody, id)
+        StackingContextId::new_of_type(id, FragmentType::FragmentBody)
     }
 
+    #[inline(always)]
     pub fn new_of_type(id: usize, fragment_type: FragmentType) -> StackingContextId {
-        StackingContextId(fragment_type, id)
+        debug_assert_eq!(id & fragment_type as usize, 0);
+        StackingContextId(id | fragment_type as usize)
     }
 }
 
 #[derive(Copy, Clone, HeapSizeOf, Deserialize, Serialize)]
 pub struct WebRenderImageInfo {
     pub width: u32,
     pub height: u32,
     pub format: PixelFormat,
--- a/servo/tests/unit/layout/size_of.rs
+++ b/servo/tests/unit/layout/size_of.rs
@@ -3,17 +3,17 @@
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 use layout::Fragment;
 use layout::ServoThreadSafeLayoutNode;
 use std::mem::size_of;
 
 #[test]
 fn test_size_of_fragment() {
-    let expected = 168;
+    let expected = 160;
     let actual = size_of::<Fragment>();
 
     if actual < expected {
         panic!("Your changes have decreased the stack size of layout::fragment::Fragment \
                 from {} to {}. Good work! Please update the size in tests/unit/layout/size_of.rs",
                 expected, actual);
     }