From 45ba167030f7bf746b61e61eae57a89b528ff6c9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emilio=20Cobos=20=C3=81lvarez?= Date: Tue, 6 Feb 2018 22:19:12 +0100 Subject: [PATCH] style: Make MozLength / MaxLength a bit more clear and do a bit less work. --- components/style/values/computed/length.rs | 1 + components/style/values/specified/length.rs | 26 ++++++++++++++++----- 2 files changed, 21 insertions(+), 6 deletions(-) diff --git a/components/style/values/computed/length.rs b/components/style/values/computed/length.rs index 49db7201a39..b130b68eb98 100644 --- a/components/style/values/computed/length.rs +++ b/components/style/values/computed/length.rs @@ -888,6 +888,7 @@ pub enum MozLength { impl MozLength { /// Returns the `auto` value. + #[inline] pub fn auto() -> Self { MozLength::LengthOrPercentageOrAuto(LengthOrPercentageOrAuto::Auto) } diff --git a/components/style/values/specified/length.rs b/components/style/values/specified/length.rs index 9ac32c208d9..b1d7a19e2c5 100644 --- a/components/style/values/specified/length.rs +++ b/components/style/values/specified/length.rs @@ -1131,9 +1131,16 @@ impl MozLength { input: &mut Parser<'i, 't>, allow_quirks: AllowQuirks, ) -> Result> { - input.try(ExtremumLength::parse).map(MozLength::ExtremumLength) - .or_else(|_| input.try(|i| LengthOrPercentageOrAuto::parse_non_negative_quirky(context, i, allow_quirks)) - .map(MozLength::LengthOrPercentageOrAuto)) + if let Ok(l) = input.try(ExtremumLength::parse) { + return Ok(MozLength::ExtremumLength(l)); + } + + let length = LengthOrPercentageOrAuto::parse_non_negative_quirky( + context, + input, + allow_quirks, + )?; + Ok(MozLength::LengthOrPercentageOrAuto(length)) } } @@ -1158,8 +1165,15 @@ impl MaxLength { input: &mut Parser<'i, 't>, allow_quirks: AllowQuirks, ) -> Result> { - input.try(ExtremumLength::parse).map(MaxLength::ExtremumLength) - .or_else(|_| input.try(|i| LengthOrPercentageOrNone::parse_non_negative_quirky(context, i, allow_quirks)) - .map(MaxLength::LengthOrPercentageOrNone)) + if let Ok(l) = input.try(ExtremumLength::parse) { + return Ok(MaxLength::ExtremumLength(l)); + } + + let length = LengthOrPercentageOrNone::parse_non_negative_quirky( + context, + input, + allow_quirks, + )?; + Ok(MaxLength::LengthOrPercentageOrNone(length)) } }