author | Xidorn Quan <me@upsuper.org> |
Sun, 29 Apr 2018 09:03:31 +1000 | |
changeset 416175 | cebd5132edfc1f48cba9ebb4561925ed4c710876 |
parent 416174 | 5edb30a5ac7b2382b6d412ce90817e7bc782d529 |
child 416176 | 543c9e49bfe5df7547448a28ebc663ef1620f406 |
push id | 33918 |
push user | nerli@mozilla.com |
push date | Sun, 29 Apr 2018 09:47:13 +0000 |
treeherder | mozilla-central@afbec7f03bd8 [default view] [failures only] |
perfherder | [talos] [build metrics] [platform microbench] (compared to previous push) |
reviewers | emilio |
bugs | 1434130 |
milestone | 61.0a1 |
first release with | nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
|
last release without | nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
|
--- a/servo/components/style_traits/values.rs +++ b/servo/components/style_traits/values.rs @@ -168,35 +168,29 @@ where pub fn new(inner: &'a mut CssWriter<'b, W>, separator: &'static str) -> Self { if inner.prefix.is_none() { // See comment in `item`. inner.prefix = Some(""); } Self { inner, separator } } - /// Serialises a CSS value, writing any separator as necessary. - /// - /// The separator is never written before any `item` produces any output, - /// and is written in subsequent calls only if the `item` produces some - /// output on its own again. This lets us handle `Option<T>` fields by - /// just not printing anything on `None`. #[inline] - pub fn item<T>(&mut self, item: &T) -> fmt::Result + fn write_item<F>(&mut self, f: F) -> fmt::Result where - T: ToCss, + F: FnOnce(&mut CssWriter<'b, W>) -> fmt::Result { let old_prefix = self.inner.prefix; if old_prefix.is_none() { // If there is no prefix in the inner writer, a previous // call to this method produced output, which means we need // to write the separator next time we produce output again. self.inner.prefix = Some(self.separator); } - item.to_css(&mut self.inner)?; + f(self.inner)?; match (old_prefix, self.inner.prefix) { (_, None) => { // This call produced output and cleaned up after itself. } (None, Some(p)) => { // Some previous call to `item` produced output, // but this one did not, prefix should be the same as // the one we set. @@ -208,16 +202,39 @@ where (Some(old), Some(new)) => { // No previous call to `item` produced output, and this one // either. debug_assert_eq!(old, new); } } Ok(()) } + + /// Serialises a CSS value, writing any separator as necessary. + /// + /// The separator is never written before any `item` produces any output, + /// and is written in subsequent calls only if the `item` produces some + /// output on its own again. This lets us handle `Option<T>` fields by + /// just not printing anything on `None`. + #[inline] + pub fn item<T>(&mut self, item: &T) -> fmt::Result + where + T: ToCss, + { + self.write_item(|inner| item.to_css(inner)) + } + + /// Writes a string as-is (i.e. not escaped or wrapped in quotes) + /// with any separator as necessary. + /// + /// See SequenceWriter::item. + #[inline] + pub fn raw_item(&mut self, item: &str) -> fmt::Result { + self.write_item(|inner| inner.write_str(item)) + } } /// A wrapper type that implements `ToCss` by printing its inner field. pub struct Verbatim<'a, T>(pub &'a T) where T: ?Sized + 'a; impl<'a, T> ToCss for Verbatim<'a, T>