Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cleanups in autoarray helper #12458

Merged
merged 4 commits into from Jul 16, 2016
Merged
Changes from 1 commit
Commits
File filter...
Filter file types
Jump to…
Jump to file
Failed to load files.

Always

Just for now

Add allow_empty to vector_longhand

  • Loading branch information
Manishearth committed Jul 15, 2016
commit b6edae2f5e37c57245b150af349d6f7380a650cc
@@ -41,11 +41,11 @@
to True for cases where Servo takes a single value
and Stylo supports vector values.

If the computed value is the same as the specified value,
setting computed_is_specified to True will introduce additional
optimizations
Setting allow_empty to False allows for cases where the vector
is empty. The grammar for these is usually "none | <thing> [ , <thing> ]*".
We assume that the default/initial value is an empty vector for these.
</%doc>
<%def name="vector_longhand(name, gecko_only=False, **kwargs)">
<%def name="vector_longhand(name, gecko_only=False, allow_empty=False, **kwargs)">
<%call expr="longhand(name, **kwargs)">
% if product == "gecko" or not gecko_only:
use cssparser::ToCss;
@@ -68,10 +68,15 @@

impl ToCss for computed_value::T {
fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
if !self.0.is_empty() {
try!(self.0[0].to_css(dest));
let mut iter = self.0.iter();
if let Some(val) = iter.next() {
try!(val.to_css(dest));
} else {
% if allow_empty:
try!(dest.write_str("none"));
% endif
}
for i in self.0.iter().skip(1) {
for i in iter {
try!(dest.write_str(", "));
try!(i.to_css(dest));
}
@@ -85,23 +90,42 @@

impl ToCss for SpecifiedValue {
fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
if !self.0.is_empty() {
try!(self.0[0].to_css(dest))
let mut iter = self.0.iter();
if let Some(val) = iter.next() {
try!(val.to_css(dest));
} else {
% if allow_empty:
try!(dest.write_str("none"));
% endif
}
for i in self.0.iter().skip(1) {
for i in iter {
try!(dest.write_str(", "));
try!(i.to_css(dest));
}
Ok(())
}
}
pub fn get_initial_value() -> computed_value::T {
computed_value::T(vec![single_value::get_initial_value()])
% if allow_empty:
computed_value::T(vec![])
% else:
computed_value::T(vec![single_value::get_initial_value()])
% endif
}
pub fn parse(context: &ParserContext, input: &mut Parser) -> Result<SpecifiedValue, ()> {
input.parse_comma_separated(|parser| {
single_value::parse(context, parser)
}).map(|ok| SpecifiedValue(ok))
% if allow_empty:
if input.try(|input| input.expect_ident_matching("none")).is_ok() {
Ok(SpecifiedValue(Vec::new()))
} else {
input.parse_comma_separated(|parser| {
single_value::parse(context, parser)
}).map(SpecifiedValue)
}
% else:
input.parse_comma_separated(|parser| {
single_value::parse(context, parser)
}).map(SpecifiedValue)
% endif
}
impl ToComputedValue for SpecifiedValue {
type ComputedValue = computed_value::T;
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.