servo: Merge #15178 - Fix serialization of CalcLengthOrPercentage (from canaltinova:calc); r=Wafflespeanut
authorNazım Can Altınova <canaltinova@gmail.com>
Thu, 26 Jan 2017 12:46:08 -0800
changeset 340658 fc50a559a23609730db4028c3c2f1456c6a89799
parent 340657 05321bfcf7b81d7399d224779b93a2657600b4b9
child 340659 a042e6c30232d00476cfc33877533f24d2e715dc
push id31307
push usergszorc@mozilla.com
push dateSat, 04 Feb 2017 00:59:06 +0000
treeherdermozilla-central@94079d43835f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersWafflespeanut
servo: Merge #15178 - Fix serialization of CalcLengthOrPercentage (from canaltinova:calc); r=Wafflespeanut <!-- Please describe your changes on the following line: --> --- <!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `__` with appropriate data: --> - [X] `./mach build -d` does not report any errors - [X] `./mach test-tidy` does not report any errors - [X] These changes fix #15168 (github issue number if applicable). <!-- Either: --> - [x] There are tests for these changes OR - [ ] These changes do not require tests because _____ <!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. --> Source-Repo: https://github.com/servo/servo Source-Revision: 5427e68572c034e6a12ca9766563bda88ee0c610
servo/components/style/values/specified/length.rs
--- a/servo/components/style/values/specified/length.rs
+++ b/servo/components/style/values/specified/length.rs
@@ -756,30 +756,16 @@ impl HasViewportPercentage for CalcLengt
         self.vw.is_some() || self.vh.is_some() ||
             self.vmin.is_some() || self.vmax.is_some()
     }
 }
 
 impl ToCss for CalcLengthOrPercentage {
     #[allow(unused_assignments)]
     fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
-        macro_rules! count {
-            ( $( $val:ident ),* ) => {
-                {
-                    let mut count = 0;
-                    $(
-                        if let Some(_) = self.$val {
-                            count += 1;
-                        }
-                    )*
-                    count
-                 }
-            };
-        }
-
         let mut first_value = true;
         macro_rules! first_value_check {
             () => {
                 if !first_value {
                     try!(dest.write_str(" + "));
                 } else {
                     first_value = false;
                 }
@@ -793,39 +779,30 @@ impl ToCss for CalcLengthOrPercentage {
                         first_value_check!();
                         try!(val.to_css(dest));
                         try!(dest.write_str(stringify!($val)));
                     }
                 )*
             };
         }
 
-        let count = count!(ch, em, ex, absolute, rem, vh, vmax, vmin, vw, percentage);
-        assert!(count > 0);
-
-        if count > 1 {
-           try!(write!(dest, "calc("));
-        }
+        try!(write!(dest, "calc("));
 
         serialize!(ch, em, ex, rem, vh, vmax, vmin, vw);
         if let Some(val) = self.absolute {
             first_value_check!();
             try!(val.to_css(dest));
         }
 
         if let Some(val) = self.percentage {
             first_value_check!();
             try!(write!(dest, "{}%", val * 100.));
         }
 
-        if count > 1 {
-           try!(write!(dest, ")"));
-        }
-
-        Ok(())
+        write!(dest, ")")
      }
 }
 
 /// A percentage value.
 ///
 /// [0 .. 100%] maps to [0.0 .. 1.0]
 #[derive(Clone, PartialEq, Copy, Debug)]
 #[cfg_attr(feature = "servo", derive(HeapSizeOf))]