From a4fc2fb242bb70a2cf8a09c7112fed00e1786495 Mon Sep 17 00:00:00 2001 From: Patrick Walton Date: Thu, 26 Sep 2013 21:31:55 -0700 Subject: [PATCH] Inline all the things --- complete.rs | 39 +++++++++++++++++++++++++++++++++++ computed.rs | 59 +++++++++++++++++++++++++++++++++++++++++++++++++++++ select.rs | 1 + 3 files changed, 99 insertions(+) diff --git a/complete.rs b/complete.rs index 271815b..4b2af32 100644 --- a/complete.rs +++ b/complete.rs @@ -82,6 +82,7 @@ impl<'self> CompleteSelectResults { } } + #[inline(always)] pub fn computed_style(&'self self) -> CompleteStyle<'self> { CompleteStyle { inner: self.inner.computed_style() @@ -97,117 +98,146 @@ impl<'self> CompleteStyle<'self> { // CSS 2.1, Section 8 - Box model + #[inline(always)] pub fn margin_top(&self) -> CSSMargin { strip(self.inner.margin_top()) } + #[inline(always)] pub fn margin_right(&self) -> CSSMargin { strip(self.inner.margin_right()) } + #[inline(always)] pub fn margin_bottom(&self) -> CSSMargin { strip(self.inner.margin_bottom()) } + #[inline(always)] pub fn margin_left(&self) -> CSSMargin { strip(self.inner.margin_left()) } + #[inline(always)] pub fn padding_top(&self) -> CSSPadding { strip(self.inner.padding_top()) } + #[inline(always)] pub fn padding_right(&self) -> CSSPadding { strip(self.inner.padding_right()) } + #[inline(always)] pub fn padding_bottom(&self) -> CSSPadding { strip(self.inner.padding_bottom()) } + #[inline(always)] pub fn padding_left(&self) -> CSSPadding { strip(self.inner.padding_left()) } + #[inline(always)] pub fn border_top_style(&self) -> CSSBorderStyle { strip(self.inner.border_top_style()) } + #[inline(always)] pub fn border_right_style(&self) -> CSSBorderStyle { strip(self.inner.border_right_style()) } + + #[inline(always)] pub fn border_bottom_style(&self) -> CSSBorderStyle { strip(self.inner.border_bottom_style()) } + #[inline(always)] pub fn border_left_style(&self) -> CSSBorderStyle { strip(self.inner.border_left_style()) } + #[inline(always)] pub fn border_top_width(&self) -> CSSBorderWidth { strip(self.inner.border_top_width()) } + #[inline(always)] pub fn border_right_width(&self) -> CSSBorderWidth { strip(self.inner.border_right_width()) } + #[inline(always)] pub fn border_bottom_width(&self) -> CSSBorderWidth { strip(self.inner.border_bottom_width()) } + #[inline(always)] pub fn border_left_width(&self) -> CSSBorderWidth { strip(self.inner.border_left_width()) } + #[inline(always)] pub fn border_top_color(&self) -> Color { strip(self.inner.border_top_color()) } + #[inline(always)] pub fn border_right_color(&self) -> Color { strip(self.inner.border_right_color()) } + #[inline(always)] pub fn border_bottom_color(&self) -> Color { strip(self.inner.border_bottom_color()) } + #[inline(always)] pub fn border_left_color(&self) -> Color { strip(self.inner.border_left_color()) } // CSS 2.1, Section 9 - Visual formatting model + #[inline(always)] pub fn display(&self, root: bool) -> CSSDisplay { strip(self.inner.display(root)) } + #[inline(always)] pub fn position(&self) -> CSSPosition { strip(self.inner.position()) } + #[inline(always)] pub fn float(&self) -> CSSFloat { strip(self.inner.float()) } + #[inline(always)] pub fn clear(&self) -> CSSClear { strip(self.inner.clear()) } // CSS 2.1, Section 10 - Visual formatting model details + #[inline(always)] pub fn width(&self) -> CSSWidth { strip(self.inner.width()) } + #[inline(always)] pub fn height(&self) -> CSSHeight { strip(self.inner.height()) } + #[inline(always)] pub fn line_height(&self) -> CSSLineHeight { strip(self.inner.line_height()) } + #[inline(always)] pub fn vertical_align(&self) -> CSSVerticalAlign { strip(self.inner.vertical_align()) } @@ -220,38 +250,46 @@ impl<'self> CompleteStyle<'self> { // CSS 2.1, Section 14 - Colors and Backgrounds + #[inline(always)] pub fn background_color(&self) -> Color { strip(self.inner.background_color()) } + #[inline(always)] pub fn color(&self) -> Color { strip(self.inner.color()) } // CSS 2.1, Section 15 - Fonts + #[inline(always)] pub fn font_family(&self) -> ~[CSSFontFamily] { strip(self.inner.font_family()) } + #[inline(always)] pub fn font_style(&self) -> CSSFontStyle { strip(self.inner.font_style()) } + #[inline(always)] pub fn font_weight(&self) -> CSSFontWeight { strip(self.inner.font_weight()) } + #[inline(always)] pub fn font_size(&self) -> CSSFontSize { strip(self.inner.font_size()) } + #[inline(always)] pub fn text_decoration(&self) -> CSSTextDecoration{ strip(self.inner.text_decoration()) } // CSS 2.1, Section 16 - Text + #[inline(always)] pub fn text_align(&self) -> CSSTextAlign { strip(self.inner.text_align()) } @@ -262,6 +300,7 @@ impl<'self> CompleteStyle<'self> { } +#[inline] fn strip(value: CSSValue) -> T { match value { Inherit => fail!(~"unexpected 'inherit' value in complete style"), diff --git a/computed.rs b/computed.rs index f9f06d8..43ec317 100644 --- a/computed.rs +++ b/computed.rs @@ -17,118 +17,146 @@ impl<'self> ComputedStyle<'self> { // CSS 2.1, Section 8 - Box model + #[inline] pub fn margin_top(&self) -> CSSValue { convert_net_margin(self.inner.margin_top()) } + #[inline] pub fn margin_right(&self) -> CSSValue { convert_net_margin(self.inner.margin_right()) } + #[inline] pub fn margin_bottom(&self) -> CSSValue { convert_net_margin(self.inner.margin_bottom()) } + #[inline] pub fn margin_left(&self) -> CSSValue { convert_net_margin(self.inner.margin_left()) } + #[inline] pub fn padding_top(&self) -> CSSValue { convert_net_padding(self.inner.padding_top()) } + #[inline] pub fn padding_right(&self) -> CSSValue { convert_net_padding(self.inner.padding_right()) } + #[inline] pub fn padding_bottom(&self) -> CSSValue { convert_net_padding(self.inner.padding_bottom()) } + #[inline] pub fn padding_left(&self) -> CSSValue { convert_net_padding(self.inner.padding_left()) } + #[inline] pub fn border_top_style(&self) -> CSSValue { convert_net_border_style(self.inner.border_top_style()) } + #[inline] pub fn border_right_style(&self) -> CSSValue { convert_net_border_style(self.inner.border_right_style()) } + #[inline] pub fn border_bottom_style(&self) -> CSSValue { convert_net_border_style(self.inner.border_bottom_style()) } + #[inline] pub fn border_left_style(&self) -> CSSValue { convert_net_border_style(self.inner.border_left_style()) } + #[inline] pub fn border_top_width(&self) -> CSSValue { convert_net_border_width(self.inner.border_top_width()) } + #[inline] pub fn border_right_width(&self) -> CSSValue { convert_net_border_width(self.inner.border_right_width()) } + #[inline] pub fn border_bottom_width(&self) -> CSSValue { convert_net_border_width(self.inner.border_bottom_width()) } + #[inline] pub fn border_left_width(&self) -> CSSValue { convert_net_border_width(self.inner.border_left_width()) } + #[inline] pub fn border_top_color(&self) -> CSSValue { convert_net_color_value(self.inner.border_top_color()) } + #[inline] pub fn border_right_color(&self) -> CSSValue { convert_net_color_value(self.inner.border_right_color()) } + #[inline] pub fn border_bottom_color(&self) -> CSSValue { convert_net_color_value(self.inner.border_bottom_color()) } + #[inline] pub fn border_left_color(&self) -> CSSValue { convert_net_color_value(self.inner.border_left_color()) } // CSS 2.1, Section 9 - Visual formatting model + #[inline] pub fn display(&self, root: bool) -> CSSValue { convert_net_display_value(self.inner.display(root)) } + #[inline] pub fn position(&self) -> CSSValue { convert_net_position_value(self.inner.position()) } + #[inline] pub fn float(&self) -> CSSValue { convert_net_float_value(self.inner.float()) } + #[inline] pub fn clear(&self) -> CSSValue { convert_net_clear_value(self.inner.clear()) } // CSS 2.1, Section 10 - Visual formatting model details + #[inline] pub fn width(&self) -> CSSValue { convert_net_width_value(self.inner.width()) } + #[inline] pub fn height(&self) -> CSSValue { convert_net_height_value(self.inner.height()) } + #[inline] pub fn line_height(&self) -> CSSValue { convert_net_line_height_value(self.inner.line_height()) } + #[inline] pub fn vertical_align(&self) -> CSSValue { convert_net_vertical_align_value(self.inner.vertical_align()) } @@ -141,38 +169,46 @@ impl<'self> ComputedStyle<'self> { // CSS 2.1, Section 14 - Colors and Backgrounds + #[inline] pub fn background_color(&self) -> CSSValue { convert_net_color_value(self.inner.background_color()) } + #[inline] pub fn color(&self) -> CSSValue { convert_net_color_value(self.inner.color()) } // CSS 2.1, Section 15 - Fonts + #[inline] pub fn font_family(&self) -> CSSValue<~[CSSFontFamily]> { convert_net_font_family_value(self.inner.font_family()) } + #[inline] pub fn font_style(&self) -> CSSValue { convert_net_font_style_value(self.inner.font_style()) } + #[inline] pub fn font_weight(&self) -> CSSValue { convert_net_font_weight_value(self.inner.font_weight()) } + #[inline] pub fn font_size(&self) -> CSSValue { convert_net_font_size_value(self.inner.font_size()) } // CSS 2.1, Section 16 - Text + #[inline] pub fn text_align(&self) -> CSSValue { convert_net_text_align_value(self.inner.text_align()) } + #[inline] pub fn text_decoration(&self) -> CSSValue { convert_net_text_decoration_value(self.inner.text_decoration()) } @@ -183,10 +219,12 @@ impl<'self> ComputedStyle<'self> { } +#[inline(always)] fn convert_net_color(color: n::t::CssColor) -> Color { rgba(color.r, color.g, color.b, (color.a as float) / 255.0) } +#[inline(always)] fn convert_net_color_value(color: n::v::CssColorValue) -> CSSValue { match color { n::v::CssColorInherit => Inherit, @@ -194,6 +232,7 @@ fn convert_net_color_value(color: n::v::CssColorValue) -> CSSValue { } } +#[inline(always)] fn convert_net_border_style(style: n::v::CssBorderStyleValue) -> CSSValue { match style { n::v::CssBorderStyleInherit => Inherit, @@ -210,6 +249,7 @@ fn convert_net_border_style(style: n::v::CssBorderStyleValue) -> CSSValue CSSValue { match width { n::v::CssBorderWidthInherit => Inherit, @@ -220,6 +260,7 @@ fn convert_net_border_width(width: n::v::CssBorderWidthValue) -> CSSValue CSSValue { match margin { n::v::CssMarginInherit => Inherit, @@ -234,6 +275,7 @@ fn convert_net_margin(margin: n::v::CssMarginValue) -> CSSValue { } } +#[inline(always)] fn convert_net_padding(padding: n::v::CssPaddingValue) -> CSSValue { match padding { n::v::CssPaddingInherit => Inherit, @@ -247,6 +289,7 @@ fn convert_net_padding(padding: n::v::CssPaddingValue) -> CSSValue { } } +#[inline(always)] fn convert_net_width_value(value: n::v::CssWidthValue) -> CSSValue { match value { n::v::CssWidthInherit => Inherit, @@ -261,6 +304,7 @@ fn convert_net_width_value(value: n::v::CssWidthValue) -> CSSValue { } } +#[inline(always)] fn convert_net_height_value(value: n::v::CssHeightValue) -> CSSValue { match value { n::v::CssHeightInherit => Inherit, @@ -275,6 +319,7 @@ fn convert_net_height_value(value: n::v::CssHeightValue) -> CSSValue } } +#[inline(always)] fn convert_net_display_value(value: n::v::CssDisplayValue) -> CSSValue { match value { n::v::CssDisplayInherit => Inherit, @@ -297,6 +342,7 @@ fn convert_net_display_value(value: n::v::CssDisplayValue) -> CSSValue CSSValue { match value { n::v::CssFloatInherit => Inherit, @@ -306,6 +352,7 @@ fn convert_net_float_value(value: n::v::CssFloatValue) -> CSSValue { } } +#[inline(always)] fn convert_net_clear_value(value: n::v::CssClearValue) -> CSSValue { match value { n::v::CssClearInherit => Inherit, @@ -316,6 +363,7 @@ fn convert_net_clear_value(value: n::v::CssClearValue) -> CSSValue { } } +#[inline(always)] fn convert_net_position_value(value: n::v::CssPositionValue) -> CSSValue { match value { n::v::CssPositionInherit => Inherit, @@ -326,6 +374,7 @@ fn convert_net_position_value(value: n::v::CssPositionValue) -> CSSValue CSSValue<~[CSSFontFamily]> { use units::{Serif, SansSerif, Cursive, Fantasy, Monospace}; @@ -340,6 +389,7 @@ fn convert_net_font_family_value(value: n::v::CssFontFamilyValue) -> CSSValue<~[ } } +#[inline(always)] fn convert_net_font_size_value(value: n::v::CssFontSizeValue) -> CSSValue { use units::*; @@ -363,6 +413,7 @@ fn convert_net_font_size_value(value: n::v::CssFontSizeValue) -> CSSValue CSSValue { match value { n::v::CssFontStyleInherit => Inherit, @@ -372,6 +423,7 @@ fn convert_net_font_style_value(value: n::v::CssFontStyleValue) -> CSSValue CSSValue { match value { n::v::CssFontWeightInherit => Inherit, @@ -391,6 +443,7 @@ fn convert_net_font_weight_value(value: n::v::CssFontWeightValue) -> CSSValue CSSValue { match value { n::v::CssTextAlignInherit => Inherit, @@ -406,6 +459,7 @@ fn convert_net_text_align_value(value: n::v::CssTextAlignValue) -> CSSValue CSSValue { match value { n::v::CssTextDecorationInherit => Inherit, @@ -417,6 +471,7 @@ fn convert_net_text_decoration_value(value: n::v::CssTextDecorationValue) -> CSS } } +#[inline(always)] fn convert_net_line_height_value(value: n::v::CssLineHeightValue) -> CSSValue { match value { n::v::CssLineHeightInherit => Inherit, @@ -431,6 +486,7 @@ fn convert_net_line_height_value(value: n::v::CssLineHeightValue) -> CSSValue CSSValue { match value { n::v::CssVerticalAlignInherit => Inherit, @@ -451,6 +507,7 @@ fn convert_net_vertical_align_value(value: n::v::CssVerticalAlignValue) -> CSSVa } } +#[inline(always)] fn convert_net_unit_to_length(unit: n::t::CssUnit) -> Length { match convert_net_unit_to_length_or_percent(unit) { Left(v) => v, @@ -458,6 +515,8 @@ fn convert_net_unit_to_length(unit: n::t::CssUnit) -> Length { } } +// Always inline due to SCCP possibilities. +#[inline(always)] fn convert_net_unit_to_length_or_percent(unit: n::t::CssUnit) -> Either { match unit { n::t::CssUnitPx(l) => Left(Px(css_fixed_to_float(l))), diff --git a/select.rs b/select.rs index 9077ee7..8e3cddf 100644 --- a/select.rs +++ b/select.rs @@ -84,6 +84,7 @@ pub struct SelectResults { impl<'self> SelectResults { /** Retrieve the computed style of a single pseudo-element */ + #[inline] pub fn computed_style(&'self self) -> ComputedStyle<'self> { ComputedStyle { inner: self.inner.computed_style(n::s::CssPseudoElementNone)