No bug - Simplify some code in NoCalcLength::parse_dimension. r=emilio
authorXidorn Quan <me@upsuper.org>
Thu, 16 Aug 2018 09:34:43 +0000
changeset 486984 4f1eb8d888be2f446f9108b2c08f211045c532e5
parent 486983 52c33d6997c37f71820c5e454530dea0982bbc0c
child 486985 7574547bff847ef8e5374afe683abf1bbc093ac0
push id9719
push userffxbld-merge
push dateFri, 24 Aug 2018 17:49:46 +0000
treeherdermozilla-beta@719ec98fba77 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersemilio
milestone63.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
No bug - Simplify some code in NoCalcLength::parse_dimension. r=emilio Differential Revision: https://phabricator.services.mozilla.com/D3473
servo/components/style/values/specified/length.rs
--- a/servo/components/style/values/specified/length.rs
+++ b/servo/components/style/values/specified/length.rs
@@ -416,56 +416,44 @@ impl Mul<CSSFloat> for NoCalcLength {
 
 impl NoCalcLength {
     /// Parse a given absolute or relative dimension.
     pub fn parse_dimension(
         context: &ParserContext,
         value: CSSFloat,
         unit: &str,
     ) -> Result<Self, ()> {
-        match_ignore_ascii_case! { unit,
-            "px" => Ok(NoCalcLength::Absolute(AbsoluteLength::Px(value))),
-            "in" => Ok(NoCalcLength::Absolute(AbsoluteLength::In(value))),
-            "cm" => Ok(NoCalcLength::Absolute(AbsoluteLength::Cm(value))),
-            "mm" => Ok(NoCalcLength::Absolute(AbsoluteLength::Mm(value))),
-            "q" => Ok(NoCalcLength::Absolute(AbsoluteLength::Q(value))),
-            "pt" => Ok(NoCalcLength::Absolute(AbsoluteLength::Pt(value))),
-            "pc" => Ok(NoCalcLength::Absolute(AbsoluteLength::Pc(value))),
+        Ok(match_ignore_ascii_case! { unit,
+            "px" => NoCalcLength::Absolute(AbsoluteLength::Px(value)),
+            "in" => NoCalcLength::Absolute(AbsoluteLength::In(value)),
+            "cm" => NoCalcLength::Absolute(AbsoluteLength::Cm(value)),
+            "mm" => NoCalcLength::Absolute(AbsoluteLength::Mm(value)),
+            "q" => NoCalcLength::Absolute(AbsoluteLength::Q(value)),
+            "pt" => NoCalcLength::Absolute(AbsoluteLength::Pt(value)),
+            "pc" => NoCalcLength::Absolute(AbsoluteLength::Pc(value)),
             // font-relative
-            "em" => Ok(NoCalcLength::FontRelative(FontRelativeLength::Em(value))),
-            "ex" => Ok(NoCalcLength::FontRelative(FontRelativeLength::Ex(value))),
-            "ch" => Ok(NoCalcLength::FontRelative(FontRelativeLength::Ch(value))),
-            "rem" => Ok(NoCalcLength::FontRelative(FontRelativeLength::Rem(value))),
+            "em" => NoCalcLength::FontRelative(FontRelativeLength::Em(value)),
+            "ex" => NoCalcLength::FontRelative(FontRelativeLength::Ex(value)),
+            "ch" => NoCalcLength::FontRelative(FontRelativeLength::Ch(value)),
+            "rem" => NoCalcLength::FontRelative(FontRelativeLength::Rem(value)),
             // viewport percentages
-            "vw" => {
-                if context.in_page_rule() {
-                    return Err(())
-                }
-                Ok(NoCalcLength::ViewportPercentage(ViewportPercentageLength::Vw(value)))
-            },
-            "vh" => {
-                if context.in_page_rule() {
-                    return Err(())
-                }
-                Ok(NoCalcLength::ViewportPercentage(ViewportPercentageLength::Vh(value)))
-            },
-            "vmin" => {
-                if context.in_page_rule() {
-                    return Err(())
-                }
-                Ok(NoCalcLength::ViewportPercentage(ViewportPercentageLength::Vmin(value)))
-            },
-            "vmax" => {
-                if context.in_page_rule() {
-                    return Err(())
-                }
-                Ok(NoCalcLength::ViewportPercentage(ViewportPercentageLength::Vmax(value)))
-            },
-            _ => Err(())
-        }
+            "vw" if !context.in_page_rule() => {
+                NoCalcLength::ViewportPercentage(ViewportPercentageLength::Vw(value))
+            }
+            "vh" if !context.in_page_rule() => {
+                NoCalcLength::ViewportPercentage(ViewportPercentageLength::Vh(value))
+            }
+            "vmin" if !context.in_page_rule() => {
+                NoCalcLength::ViewportPercentage(ViewportPercentageLength::Vmin(value))
+            }
+            "vmax" if !context.in_page_rule() => {
+                NoCalcLength::ViewportPercentage(ViewportPercentageLength::Vmax(value))
+            }
+            _ => return Err(())
+        })
     }
 
     #[inline]
     /// Returns a `zero` length.
     pub fn zero() -> NoCalcLength {
         NoCalcLength::Absolute(AbsoluteLength::Px(0.))
     }