style: Early return in a couple of places to deindent some code.

MozReview-Commit-ID: 8hDAKZANOro
Signed-off-by: Emilio Cobos Álvarez <emilio@crisal.io>
This commit is contained in:
Emilio Cobos Álvarez 2017-09-25 14:53:58 +02:00
parent d9cec56d71
commit 3067d2e320
No known key found for this signature in database
GPG key ID: 056B727BB9C1027C

View file

@ -182,57 +182,57 @@ ${helpers.predefined_type("marker-end", "UrlOrNone", "Either::Second(None_)",
pub fn parse<'i, 't>(_context: &ParserContext, input: &mut Parser<'i, 't>) pub fn parse<'i, 't>(_context: &ParserContext, input: &mut Parser<'i, 't>)
-> Result<SpecifiedValue,ParseError<'i>> { -> Result<SpecifiedValue,ParseError<'i>> {
if let Ok(()) = input.try(|i| i.expect_ident_matching("normal")) { if let Ok(()) = input.try(|i| i.expect_ident_matching("normal")) {
Ok(SpecifiedValue(0)) return Ok(SpecifiedValue(0))
} else { }
let mut value = 0;
// bitfield representing what we've seen so far
// bit 1 is fill, bit 2 is stroke, bit 3 is markers
let mut seen = 0;
let mut pos = 0;
loop { let mut value = 0;
let result: Result<_, ParseError> = input.try(|i| { // bitfield representing what we've seen so far
try_match_ident_ignore_ascii_case! { i.expect_ident()?, // bit 1 is fill, bit 2 is stroke, bit 3 is markers
"fill" => Ok(FILL), let mut seen = 0;
"stroke" => Ok(STROKE), let mut pos = 0;
"markers" => Ok(MARKERS),
}
});
match result { loop {
Ok(val) => { let result: Result<_, ParseError> = input.try(|i| {
if (seen & (1 << val)) != 0 { try_match_ident_ignore_ascii_case! { i.expect_ident()?,
// don't parse the same ident twice "fill" => Ok(FILL),
return Err(StyleParseError::UnspecifiedError.into()) "stroke" => Ok(STROKE),
} else { "markers" => Ok(MARKERS),
value |= val << (pos * SHIFT);
seen |= 1 << val;
pos += 1;
}
}
Err(_) => break,
} }
} });
if value == 0 { match result {
// couldn't find any keyword Ok(val) => {
Err(StyleParseError::UnspecifiedError.into()) if (seen & (1 << val)) != 0 {
} else { // don't parse the same ident twice
// fill in rest return Err(StyleParseError::UnspecifiedError.into())
for i in pos..COUNT {
for paint in &ALL {
// if not seen, set bit at position, mark as seen
if (seen & (1 << paint)) == 0 {
seen |= 1 << paint;
value |= paint << (i * SHIFT);
break;
}
} }
}
Ok(SpecifiedValue(value)) value |= val << (pos * SHIFT);
seen |= 1 << val;
pos += 1;
}
Err(_) => break,
} }
} }
if value == 0 {
// couldn't find any keyword
return Err(StyleParseError::UnspecifiedError.into())
}
// fill in rest
for i in pos..COUNT {
for paint in &ALL {
// if not seen, set bit at position, mark as seen
if (seen & (1 << paint)) == 0 {
seen |= 1 << paint;
value |= paint << (i * SHIFT);
break;
}
}
}
Ok(SpecifiedValue(value))
} }
impl ToCss for SpecifiedValue { impl ToCss for SpecifiedValue {