mirror of
https://github.com/servo/servo.git
synced 2025-08-12 00:45:33 +01:00
Auto merge of #19838 - servo:rm-sequence-writer-as-it-was, r=emilio
Make ToCss' SequenceWriter not monomorphise like a maniac anymore <!-- Reviewable:start --> This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/19838) <!-- Reviewable:end -->
This commit is contained in:
commit
6b2e5283c9
89 changed files with 931 additions and 672 deletions
|
@ -17,10 +17,9 @@ use custom_properties::CustomPropertiesBuilder;
|
|||
use servo_arc::{Arc, UniqueArc};
|
||||
use smallbitvec::SmallBitVec;
|
||||
use std::borrow::Cow;
|
||||
use std::{mem, ops};
|
||||
use std::cell::RefCell;
|
||||
use std::fmt::{self, Write};
|
||||
use std::mem;
|
||||
use std::ops;
|
||||
|
||||
#[cfg(feature = "servo")] use cssparser::RGBA;
|
||||
use cssparser::{CowRcStr, Parser, TokenSerializationType, serialize_identifier};
|
||||
|
@ -41,7 +40,7 @@ use selector_parser::PseudoElement;
|
|||
use selectors::parser::SelectorParseErrorKind;
|
||||
#[cfg(feature = "servo")] use servo_config::prefs::PREFS;
|
||||
use shared_lock::StylesheetGuards;
|
||||
use style_traits::{ParsingMode, ToCss, ParseError, StyleParseErrorKind};
|
||||
use style_traits::{CssWriter, ParseError, ParsingMode, StyleParseErrorKind, ToCss};
|
||||
use stylesheets::{CssRuleType, Origin, UrlExtraData};
|
||||
#[cfg(feature = "servo")] use values::Either;
|
||||
use values::generics::text::LineHeight;
|
||||
|
@ -856,9 +855,14 @@ impl ShorthandId {
|
|||
///
|
||||
/// Returns an error if writing to the stream fails, or if the declarations
|
||||
/// do not map to a shorthand.
|
||||
pub fn longhands_to_css<'a, W, I>(&self, declarations: I, dest: &mut W) -> fmt::Result
|
||||
where W: fmt::Write,
|
||||
I: Iterator<Item=&'a PropertyDeclaration>,
|
||||
pub fn longhands_to_css<'a, W, I>(
|
||||
&self,
|
||||
declarations: I,
|
||||
dest: &mut CssWriter<W>,
|
||||
) -> fmt::Result
|
||||
where
|
||||
W: Write,
|
||||
I: Iterator<Item=&'a PropertyDeclaration>,
|
||||
{
|
||||
match *self {
|
||||
ShorthandId::All => {
|
||||
|
@ -1076,8 +1080,9 @@ impl UnparsedValue {
|
|||
}
|
||||
|
||||
impl<'a, T: ToCss> ToCss for DeclaredValue<'a, T> {
|
||||
fn to_css<W>(&self, dest: &mut W) -> fmt::Result
|
||||
where W: fmt::Write,
|
||||
fn to_css<W>(&self, dest: &mut CssWriter<W>) -> fmt::Result
|
||||
where
|
||||
W: Write,
|
||||
{
|
||||
match *self {
|
||||
DeclaredValue::Value(ref inner) => inner.to_css(dest),
|
||||
|
@ -1105,8 +1110,9 @@ pub enum PropertyDeclarationId<'a> {
|
|||
}
|
||||
|
||||
impl<'a> ToCss for PropertyDeclarationId<'a> {
|
||||
fn to_css<W>(&self, dest: &mut W) -> fmt::Result
|
||||
where W: fmt::Write,
|
||||
fn to_css<W>(&self, dest: &mut CssWriter<W>) -> fmt::Result
|
||||
where
|
||||
W: Write,
|
||||
{
|
||||
match *self {
|
||||
PropertyDeclarationId::Longhand(id) => dest.write_str(id.name()),
|
||||
|
@ -1151,7 +1157,6 @@ impl<'a> PropertyDeclarationId<'a> {
|
|||
match *self {
|
||||
PropertyDeclarationId::Longhand(id) => id.name().into(),
|
||||
PropertyDeclarationId::Custom(name) => {
|
||||
use std::fmt::Write;
|
||||
let mut s = String::new();
|
||||
write!(&mut s, "--{}", name).unwrap();
|
||||
s.into()
|
||||
|
@ -1178,13 +1183,14 @@ pub enum PropertyId {
|
|||
|
||||
impl fmt::Debug for PropertyId {
|
||||
fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
|
||||
self.to_css(formatter)
|
||||
self.to_css(&mut CssWriter::new(formatter))
|
||||
}
|
||||
}
|
||||
|
||||
impl ToCss for PropertyId {
|
||||
fn to_css<W>(&self, dest: &mut W) -> fmt::Result
|
||||
where W: fmt::Write,
|
||||
fn to_css<W>(&self, dest: &mut CssWriter<W>) -> fmt::Result
|
||||
where
|
||||
W: Write,
|
||||
{
|
||||
match *self {
|
||||
PropertyId::Longhand(id) => dest.write_str(id.name()),
|
||||
|
@ -1332,7 +1338,6 @@ impl PropertyId {
|
|||
PropertyId::LonghandAlias(id, _) |
|
||||
PropertyId::Longhand(id) => id.name().into(),
|
||||
PropertyId::Custom(ref name) => {
|
||||
use std::fmt::Write;
|
||||
let mut s = String::new();
|
||||
write!(&mut s, "--{}", name).unwrap();
|
||||
s.into()
|
||||
|
@ -1465,7 +1470,7 @@ pub enum PropertyDeclaration {
|
|||
|
||||
impl fmt::Debug for PropertyDeclaration {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
self.id().to_css(f)?;
|
||||
self.id().to_css(&mut CssWriter::new(f))?;
|
||||
f.write_str(": ")?;
|
||||
|
||||
// Because PropertyDeclaration::to_css requires CssStringWriter, we can't write
|
||||
|
@ -1484,10 +1489,13 @@ impl PropertyDeclaration {
|
|||
pub fn to_css(&self, dest: &mut CssStringWriter) -> fmt::Result {
|
||||
match *self {
|
||||
% for property in data.longhands:
|
||||
PropertyDeclaration::${property.camel_case}(ref value) =>
|
||||
value.to_css(dest),
|
||||
PropertyDeclaration::${property.camel_case}(ref value) => {
|
||||
value.to_css(&mut CssWriter::new(dest))
|
||||
}
|
||||
% endfor
|
||||
PropertyDeclaration::CSSWideKeyword(_, keyword) => keyword.to_css(dest),
|
||||
PropertyDeclaration::CSSWideKeyword(_, keyword) => {
|
||||
keyword.to_css(&mut CssWriter::new(dest))
|
||||
},
|
||||
PropertyDeclaration::WithVariables(_, ref with_variables) => {
|
||||
// https://drafts.csswg.org/css-variables/#variables-in-shorthands
|
||||
match with_variables.from_shorthand {
|
||||
|
@ -1501,7 +1509,9 @@ impl PropertyDeclaration {
|
|||
}
|
||||
Ok(())
|
||||
},
|
||||
PropertyDeclaration::Custom(_, ref value) => value.borrow().to_css(dest),
|
||||
PropertyDeclaration::Custom(_, ref value) => {
|
||||
value.borrow().to_css(&mut CssWriter::new(dest))
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue