mirror of
https://github.com/servo/servo.git
synced 2025-08-03 12:40:06 +01:00
style: Use ArcSlice for quotes.
This saves the intermediate allocation. Differential Revision: https://phabricator.services.mozilla.com/D30546
This commit is contained in:
parent
bbc77e3977
commit
a109fbb7c8
9 changed files with 85 additions and 44 deletions
|
@ -10,7 +10,6 @@ use crate::values::generics::CounterStyleOrNone;
|
|||
#[cfg(feature = "gecko")]
|
||||
use crate::values::CustomIdent;
|
||||
use cssparser::{Parser, Token};
|
||||
use servo_arc::Arc;
|
||||
use style_traits::{ParseError, StyleParseErrorKind};
|
||||
|
||||
/// Specified and computed `list-style-type` property.
|
||||
|
@ -96,18 +95,20 @@ impl Parse for ListStyleType {
|
|||
ToResolvedValue,
|
||||
ToShmem,
|
||||
)]
|
||||
#[repr(C)]
|
||||
pub struct QuotePair {
|
||||
/// The opening quote.
|
||||
pub opening: Box<str>,
|
||||
pub opening: crate::OwnedStr,
|
||||
|
||||
/// The closing quote.
|
||||
pub closing: Box<str>,
|
||||
pub closing: crate::OwnedStr,
|
||||
}
|
||||
|
||||
/// Specified and computed `quotes` property.
|
||||
#[derive(
|
||||
Clone,
|
||||
Debug,
|
||||
Default,
|
||||
MallocSizeOf,
|
||||
PartialEq,
|
||||
SpecifiedValueInfo,
|
||||
|
@ -116,10 +117,11 @@ pub struct QuotePair {
|
|||
ToResolvedValue,
|
||||
ToShmem,
|
||||
)]
|
||||
#[repr(C)]
|
||||
pub struct Quotes(
|
||||
#[css(iterable, if_empty = "none")]
|
||||
#[ignore_malloc_size_of = "Arc"]
|
||||
pub Arc<Box<[QuotePair]>>,
|
||||
pub crate::ArcSlice<QuotePair>,
|
||||
);
|
||||
|
||||
impl Parse for Quotes {
|
||||
|
@ -131,24 +133,26 @@ impl Parse for Quotes {
|
|||
.try(|input| input.expect_ident_matching("none"))
|
||||
.is_ok()
|
||||
{
|
||||
return Ok(Quotes(Arc::new(Box::new([]))));
|
||||
return Ok(Self::default());
|
||||
}
|
||||
|
||||
let mut quotes = Vec::new();
|
||||
loop {
|
||||
let location = input.current_source_location();
|
||||
let opening = match input.next() {
|
||||
Ok(&Token::QuotedString(ref value)) => value.as_ref().to_owned().into_boxed_str(),
|
||||
Ok(&Token::QuotedString(ref value)) => {
|
||||
value.as_ref().to_owned().into()
|
||||
},
|
||||
Ok(t) => return Err(location.new_unexpected_token_error(t.clone())),
|
||||
Err(_) => break,
|
||||
};
|
||||
|
||||
let closing = input.expect_string()?.as_ref().to_owned().into_boxed_str();
|
||||
let closing = input.expect_string()?.as_ref().to_owned().into();
|
||||
quotes.push(QuotePair { opening, closing });
|
||||
}
|
||||
|
||||
if !quotes.is_empty() {
|
||||
Ok(Quotes(Arc::new(quotes.into_boxed_slice())))
|
||||
Ok(Quotes(crate::ArcSlice::from_iter(quotes.into_iter())))
|
||||
} else {
|
||||
Err(input.new_custom_error(StyleParseErrorKind::UnspecifiedError))
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue