script: Inline some hot functions used in flow constructions.

9% improvement in style recalc on the rainbow page.
This commit is contained in:
Patrick Walton 2014-01-30 18:05:12 -08:00
parent e2e848c6ad
commit a0fbc04ba5
3 changed files with 12 additions and 0 deletions

View file

@ -621,6 +621,7 @@ pub struct Reflector {
} }
impl Reflector { impl Reflector {
#[inline]
pub fn get_jsobject(&self) -> *JSObject { pub fn get_jsobject(&self) -> *JSObject {
self.object self.object
} }

View file

@ -208,6 +208,7 @@ impl Clone for AbstractNode {
} }
impl AbstractNode { impl AbstractNode {
#[inline]
pub fn node<'a>(&'a self) -> &'a Node { pub fn node<'a>(&'a self) -> &'a Node {
unsafe { unsafe {
let box_: *mut Box<Node> = cast::transmute(self.obj); let box_: *mut Box<Node> = cast::transmute(self.obj);
@ -215,6 +216,7 @@ impl AbstractNode {
} }
} }
#[inline]
pub fn mut_node<'a>(&'a self) -> &'a mut Node { pub fn mut_node<'a>(&'a self) -> &'a mut Node {
unsafe { unsafe {
let box_: *mut Box<Node> = cast::transmute(self.obj); let box_: *mut Box<Node> = cast::transmute(self.obj);
@ -222,14 +224,17 @@ impl AbstractNode {
} }
} }
#[inline]
pub fn parent_node(&self) -> Option<AbstractNode> { pub fn parent_node(&self) -> Option<AbstractNode> {
self.node().parent_node self.node().parent_node
} }
#[inline]
pub fn first_child(&self) -> Option<AbstractNode> { pub fn first_child(&self) -> Option<AbstractNode> {
self.node().first_child self.node().first_child
} }
#[inline]
pub fn last_child(&self) -> Option<AbstractNode> { pub fn last_child(&self) -> Option<AbstractNode> {
self.node().last_child self.node().last_child
} }
@ -316,6 +321,7 @@ impl<'a> AbstractNode {
// Convenience accessors // Convenience accessors
/// Returns the type ID of this node. Fails if this node is borrowed mutably. /// Returns the type ID of this node. Fails if this node is borrowed mutably.
#[inline]
pub fn type_id(self) -> NodeTypeId { pub fn type_id(self) -> NodeTypeId {
self.node().type_id self.node().type_id
} }

View file

@ -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 } } pub fn max(x: Au, y: Au) -> Au { if x > y { x } else { y } }
impl NumCast for Au { impl NumCast for Au {
#[inline]
fn from<T:ToPrimitive>(n: T) -> Option<Au> { fn from<T:ToPrimitive>(n: T) -> Option<Au> {
Some(Au(n.to_i32().unwrap())) Some(Au(n.to_i32().unwrap()))
} }
} }
impl ToPrimitive for Au { impl ToPrimitive for Au {
#[inline]
fn to_i64(&self) -> Option<i64> { fn to_i64(&self) -> Option<i64> {
Some(**self as i64) Some(**self as i64)
} }
#[inline]
fn to_u64(&self) -> Option<u64> { fn to_u64(&self) -> Option<u64> {
Some(**self as u64) Some(**self as u64)
} }
#[inline]
fn to_f32(&self) -> Option<f32> { fn to_f32(&self) -> Option<f32> {
(**self).to_f32() (**self).to_f32()
} }
#[inline]
fn to_f64(&self) -> Option<f64> { fn to_f64(&self) -> Option<f64> {
(**self).to_f64() (**self).to_f64()
} }