From a0fbc04ba5137b7617abd7aec15f60e0e4a92d63 Mon Sep 17 00:00:00 2001 From: Patrick Walton Date: Thu, 30 Jan 2014 18:05:12 -0800 Subject: [PATCH] script: Inline some hot functions used in flow constructions. 9% improvement in style recalc on the rainbow page. --- src/components/script/dom/bindings/utils.rs | 1 + src/components/script/dom/node.rs | 6 ++++++ src/components/util/geometry.rs | 5 +++++ 3 files changed, 12 insertions(+) diff --git a/src/components/script/dom/bindings/utils.rs b/src/components/script/dom/bindings/utils.rs index f1e69e32021..839a546862f 100644 --- a/src/components/script/dom/bindings/utils.rs +++ b/src/components/script/dom/bindings/utils.rs @@ -621,6 +621,7 @@ pub struct Reflector { } impl Reflector { + #[inline] pub fn get_jsobject(&self) -> *JSObject { self.object } diff --git a/src/components/script/dom/node.rs b/src/components/script/dom/node.rs index c1626730d56..f34c7f87cd1 100644 --- a/src/components/script/dom/node.rs +++ b/src/components/script/dom/node.rs @@ -208,6 +208,7 @@ impl Clone for AbstractNode { } impl AbstractNode { + #[inline] pub fn node<'a>(&'a self) -> &'a Node { unsafe { let box_: *mut Box = cast::transmute(self.obj); @@ -215,6 +216,7 @@ impl AbstractNode { } } + #[inline] pub fn mut_node<'a>(&'a self) -> &'a mut Node { unsafe { let box_: *mut Box = cast::transmute(self.obj); @@ -222,14 +224,17 @@ impl AbstractNode { } } + #[inline] pub fn parent_node(&self) -> Option { self.node().parent_node } + #[inline] pub fn first_child(&self) -> Option { self.node().first_child } + #[inline] pub fn last_child(&self) -> Option { self.node().last_child } @@ -316,6 +321,7 @@ impl<'a> AbstractNode { // Convenience accessors /// Returns the type ID of this node. Fails if this node is borrowed mutably. + #[inline] pub fn type_id(self) -> NodeTypeId { self.node().type_id } diff --git a/src/components/util/geometry.rs b/src/components/util/geometry.rs index 71184e5eec1..4935c802d9b 100644 --- a/src/components/util/geometry.rs +++ b/src/components/util/geometry.rs @@ -101,24 +101,29 @@ pub fn min(x: Au, y: Au) -> Au { if x < y { x } else { y } } pub fn max(x: Au, y: Au) -> Au { if x > y { x } else { y } } impl NumCast for Au { + #[inline] fn from(n: T) -> Option { Some(Au(n.to_i32().unwrap())) } } impl ToPrimitive for Au { + #[inline] fn to_i64(&self) -> Option { Some(**self as i64) } + #[inline] fn to_u64(&self) -> Option { Some(**self as u64) } + #[inline] fn to_f32(&self) -> Option { (**self).to_f32() } + #[inline] fn to_f64(&self) -> Option { (**self).to_f64() }