From f967d5a64501dc924b1ad738b837ad9858393eb9 Mon Sep 17 00:00:00 2001 From: Matt Brubeck Date: Tue, 24 May 2016 15:50:04 -0700 Subject: [PATCH] Reduce the size of StackingContextId --- components/gfx/display_list/mod.rs | 13 +++++++------ tests/unit/layout/size_of.rs | 2 +- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/components/gfx/display_list/mod.rs b/components/gfx/display_list/mod.rs index 73071d91ec03..091e9a08c5aa 100644 --- a/components/gfx/display_list/mod.rs +++ b/components/gfx/display_list/mod.rs @@ -1409,20 +1409,21 @@ pub enum FragmentType { /// 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) } } diff --git a/tests/unit/layout/size_of.rs b/tests/unit/layout/size_of.rs index 87f1dcb3d441..033916647ee0 100644 --- a/tests/unit/layout/size_of.rs +++ b/tests/unit/layout/size_of.rs @@ -8,7 +8,7 @@ use std::mem::size_of; #[test] fn test_size_of_fragment() { - let expected = 168; + let expected = 160; let actual = size_of::(); if actual < expected {