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

style: Sync changes from mozilla-central. #22143

Merged
merged 11 commits into from Nov 8, 2018

style: Make quotes property representation allocate less.

  • Loading branch information
heycam authored and emilio committed Nov 8, 2018
commit acf7b65f36057e018dc522b93e40808fb0878672
@@ -4187,9 +4187,9 @@ fn static_assert() {
UniqueRefPtr::from_addrefed(Gecko_NewStyleQuoteValues(other.0.len() as u32))
};

for (servo, gecko) in other.0.into_iter().zip(refptr.mQuotePairs.iter_mut()) {
gecko.first.assign_str(&servo.0);
gecko.second.assign_str(&servo.1);
for (servo, gecko) in other.0.iter().zip(refptr.mQuotePairs.iter_mut()) {
gecko.first.assign_str(&servo.opening);
gecko.second.assign_str(&servo.closing);
}

self.gecko.mQuotes.set_move(refptr.get())
@@ -4206,14 +4206,14 @@ fn static_assert() {
pub fn clone_quotes(&self) -> longhands::quotes::computed_value::T {
unsafe {
let ref gecko_quote_values = *self.gecko.mQuotes.mRawPtr;
longhands::quotes::computed_value::T(
longhands::quotes::computed_value::T(Arc::new(
gecko_quote_values.mQuotePairs.iter().map(|gecko_pair| {
(
gecko_pair.first.to_string().into_boxed_str(),
gecko_pair.second.to_string().into_boxed_str(),
)
values::specified::QuotePair {
opening: gecko_pair.first.to_string().into_boxed_str(),
closing: gecko_pair.second.to_string().into_boxed_str(),
}
}).collect::<Vec<_>>().into_boxed_slice()
)
))
}
}

@@ -6,26 +6,30 @@

#[cfg(feature = "gecko")]
pub use values::specified::list::ListStyleType;
pub use values::specified::list::Quotes;
pub use values::specified::list::{QuotePair, Quotes};

use servo_arc::Arc;
use values::specified::list::QuotePair;

lazy_static! {
static ref INITIAL_QUOTES: Arc<Box<[QuotePair]>> = Arc::new(
vec![
QuotePair {
opening: "\u{201c}".to_owned().into_boxed_str(),
closing: "\u{201d}".to_owned().into_boxed_str(),
},
QuotePair {
opening: "\u{2018}".to_owned().into_boxed_str(),
closing: "\u{2019}".to_owned().into_boxed_str(),
},
].into_boxed_slice()
);
}

impl Quotes {
/// Initial value for `quotes`.
///
/// FIXME(emilio): This should ideally not allocate.
#[inline]
pub fn get_initial_value() -> Quotes {
Quotes(
vec![
(
"\u{201c}".to_owned().into_boxed_str(),
"\u{201d}".to_owned().into_boxed_str(),
),
(
"\u{2018}".to_owned().into_boxed_str(),
"\u{2019}".to_owned().into_boxed_str(),
),
]
.into_boxed_slice(),
)
Quotes(INITIAL_QUOTES.clone())
}
}
@@ -69,7 +69,7 @@ pub use self::length::{LengthOrPercentageOrAuto, LengthOrPercentageOrNone, MaxLe
pub use self::length::{NonNegativeLengthOrPercentage, NonNegativeLengthOrPercentageOrAuto};
#[cfg(feature = "gecko")]
pub use self::list::ListStyleType;
pub use self::list::Quotes;
pub use self::list::{QuotePair, Quotes};
pub use self::motion::OffsetPath;
pub use self::outline::OutlineStyle;
pub use self::percentage::{NonNegativePercentage, Percentage};
@@ -6,8 +6,8 @@

use cssparser::{Parser, Token};
use parser::{Parse, ParserContext};
use std::fmt::{self, Write};
use style_traits::{CssWriter, ParseError, StyleParseErrorKind, ToCss};
use servo_arc::Arc;
use style_traits::{ParseError, StyleParseErrorKind};
#[cfg(feature = "gecko")]
use values::generics::CounterStyleOrNone;
#[cfg(feature = "gecko")]
@@ -73,41 +73,25 @@ impl Parse for ListStyleType {
}
}

/// Specified and computed `quote` property.
///
/// FIXME(emilio): It's a shame that this allocates all the time it's computed,
/// probably should just be refcounted.
/// FIXME This can probably derive ToCss.
#[derive(Clone, Debug, MallocSizeOf, PartialEq, SpecifiedValueInfo, ToComputedValue)]
pub struct Quotes(#[css(if_empty = "none")] pub Box<[(Box<str>, Box<str>)]>);

impl ToCss for Quotes {
fn to_css<W>(&self, dest: &mut CssWriter<W>) -> fmt::Result
where
W: Write,
{
let mut iter = self.0.iter();

match iter.next() {
Some(&(ref l, ref r)) => {
l.to_css(dest)?;
dest.write_char(' ')?;
r.to_css(dest)?;
},
None => return dest.write_str("none"),
}

for &(ref l, ref r) in iter {
dest.write_char(' ')?;
l.to_css(dest)?;
dest.write_char(' ')?;
r.to_css(dest)?;
}
/// A quote pair.
#[derive(Clone, Debug, MallocSizeOf, PartialEq, SpecifiedValueInfo, ToComputedValue, ToCss)]
pub struct QuotePair {
/// The opening quote.
pub opening: Box<str>,

Ok(())
}
/// The closing quote.
pub closing: Box<str>,
}

/// Specified and computed `quotes` property.
#[derive(Clone, Debug, MallocSizeOf, PartialEq, SpecifiedValueInfo, ToComputedValue, ToCss)]
pub struct Quotes(
#[css(if_empty = "none")]
#[css(iterable)]
#[ignore_malloc_size_of = "Arc"]
pub Arc<Box<[QuotePair]>>
);

impl Parse for Quotes {
fn parse<'i, 't>(
_: &ParserContext,
@@ -117,24 +101,24 @@ impl Parse for Quotes {
.try(|input| input.expect_ident_matching("none"))
.is_ok()
{
return Ok(Quotes(Vec::new().into_boxed_slice()));
return Ok(Quotes(Arc::new(Box::new([]))));
}

let mut quotes = Vec::new();
loop {
let location = input.current_source_location();
let first = match input.next() {
let opening = match input.next() {
Ok(&Token::QuotedString(ref value)) => value.as_ref().to_owned().into_boxed_str(),
Ok(t) => return Err(location.new_unexpected_token_error(t.clone())),
Err(_) => break,
};

let second = input.expect_string()?.as_ref().to_owned().into_boxed_str();
quotes.push((first, second))
let closing = input.expect_string()?.as_ref().to_owned().into_boxed_str();
quotes.push(QuotePair { opening, closing });
}

if !quotes.is_empty() {
Ok(Quotes(quotes.into_boxed_slice()))
Ok(Quotes(Arc::new(quotes.into_boxed_slice())))
} else {
Err(input.new_custom_error(StyleParseErrorKind::UnspecifiedError))
}
@@ -63,7 +63,7 @@ pub use self::length::{NoCalcLength, ViewportPercentageLength};
pub use self::length::{NonNegativeLengthOrPercentage, NonNegativeLengthOrPercentageOrAuto};
#[cfg(feature = "gecko")]
pub use self::list::ListStyleType;
pub use self::list::Quotes;
pub use self::list::{QuotePair, Quotes};
pub use self::motion::OffsetPath;
pub use self::outline::OutlineStyle;
pub use self::percentage::Percentage;
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.