Change ToCss to take a CssWriter<W>

This more concrete wrapper type can write a prefix the very first time something
is written to it. This allows removing plenty of useless monomorphisations caused
by the former W/SequenceWriter<W> pair of types.
This commit is contained in:
Anthony Ramine 2018-01-22 19:58:01 +01:00
parent 3672856efa
commit cd8f96cc9e
89 changed files with 873 additions and 533 deletions

View file

@ -11,10 +11,10 @@ use cssparser::Parser;
use hash::FnvHashMap;
use parser::{Parse, ParserContext};
use selectors::parser::SelectorParseErrorKind;
use std::fmt;
use std::fmt::{self, Write};
use std::ops::Range;
use str::HTML_SPACE_CHARACTERS;
use style_traits::{ToCss, StyleParseErrorKind, ParseError};
use style_traits::{CssWriter, ParseError, StyleParseErrorKind, ToCss};
use values::{Either, None_};
use values::computed::{CalcLengthOrPercentage, LengthOrPercentage as ComputedLengthOrPercentage};
use values::computed::{Context, Percentage, ToComputedValue};
@ -142,7 +142,10 @@ impl Position {
}
impl ToCss for Position {
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.horizontal, &self.vertical) {
(x_pos @ &PositionComponent::Side(_, Some(_)), &PositionComponent::Length(ref y_lop)) => {
x_pos.to_css(dest)?;
@ -369,7 +372,10 @@ impl LegacyPosition {
}
impl ToCss for LegacyPosition {
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,
{
self.horizontal.to_css(dest)?;
dest.write_str(" ")?;
self.vertical.to_css(dest)
@ -409,7 +415,10 @@ impl GridAutoFlow {
}
impl ToCss for GridAutoFlow {
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,
{
self.autoflow.to_css(dest)?;
if self.dense { dest.write_str(" dense")?; }
@ -584,7 +593,10 @@ impl TemplateAreas {
}
impl ToCss for TemplateAreas {
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,
{
for (i, string) in self.strings.iter().enumerate() {
if i != 0 {
dest.write_str(" ")?;