servo: Merge #16956 - stylo: Use correct counts when copying from image layers (from mbrubeck:cleanup); r=Manishearth
authorMatt Brubeck <mbrubeck@limpet.net>
Sun, 21 May 2017 14:09:52 -0500
changeset 359844 cbef0952c3416b20baee769e4dd7d194317587d6
parent 359843 ebb6631b83fce35f417b1d6ba1aa78c4b3de11d6
child 359845 fa623e714a039edc02c380a3da81ea529c9c00ec
push id31859
push userihsiao@mozilla.com
push dateMon, 22 May 2017 03:28:26 +0000
treeherdermozilla-central@367944041b55 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersManishearth
milestone55.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
servo: Merge #16956 - stylo: Use correct counts when copying from image layers (from mbrubeck:cleanup); r=Manishearth --- - [x] `./mach build -d` does not report any errors - [x] `./mach test-tidy` does not report any errors - [x] These changes do not require tests because they are code cleanup. Source-Repo: https://github.com/servo/servo Source-Revision: 460c90af8d028fac341a8d3b274fba591441dc32
servo/components/style/properties/gecko.mako.rs
--- a/servo/components/style/properties/gecko.mako.rs
+++ b/servo/components/style/properties/gecko.mako.rs
@@ -2764,29 +2764,28 @@ fn static_assert() {
 
 <%def name="simple_image_array_property(name, shorthand, field_name)">
     <%
         image_layers_field = "mImage" if shorthand == "background" else "mMask"
     %>
     pub fn copy_${shorthand}_${name}_from(&mut self, other: &Self) {
         use gecko_bindings::structs::nsStyleImageLayers_LayerType as LayerType;
 
+        let count = other.gecko.${image_layers_field}.${field_name}Count;
         unsafe {
             Gecko_EnsureImageLayersLength(&mut self.gecko.${image_layers_field},
-                                          other.gecko.${image_layers_field}.mLayers.len(),
+                                          count as usize,
                                           LayerType::${shorthand.title()});
         }
         for (layer, other) in self.gecko.${image_layers_field}.mLayers.iter_mut()
                                   .zip(other.gecko.${image_layers_field}.mLayers.iter())
-                                  .take(other.gecko.${image_layers_field}
-                                                   .${field_name}Count as usize) {
+                                  .take(count as usize) {
             layer.${field_name} = other.${field_name};
         }
-        self.gecko.${image_layers_field}.${field_name}Count =
-            other.gecko.${image_layers_field}.${field_name}Count;
+        self.gecko.${image_layers_field}.${field_name}Count = count;
     }
 
 
     pub fn set_${shorthand}_${name}<I>(&mut self, v: I)
         where I: IntoIterator<Item=longhands::${shorthand}_${name}::computed_value::single_value::T>,
               I::IntoIter: ExactSizeIterator
     {
         use gecko_bindings::structs::nsStyleImageLayers_LayerType as LayerType;
@@ -2869,33 +2868,31 @@ fn static_assert() {
             % endif
         }
     </%self:simple_image_array_property>
 
     % for orientation in ["x", "y"]:
     pub fn copy_${shorthand}_position_${orientation}_from(&mut self, other: &Self) {
         use gecko_bindings::structs::nsStyleImageLayers_LayerType as LayerType;
 
-        self.gecko.${image_layers_field}.mPosition${orientation.upper()}Count
-            = cmp::min(1, other.gecko.${image_layers_field}.mPosition${orientation.upper()}Count);
-        self.gecko.${image_layers_field}.mLayers.mFirstElement.mPosition =
-            other.gecko.${image_layers_field}.mLayers.mFirstElement.mPosition;
+        let count = other.gecko.${image_layers_field}.mPosition${orientation.upper()}Count;
+
         unsafe {
             Gecko_EnsureImageLayersLength(&mut self.gecko.${image_layers_field},
-                                          other.gecko.${image_layers_field}.mLayers.len(),
+                                          count as usize,
                                           LayerType::${shorthand.capitalize()});
         }
 
         for (layer, other) in self.gecko.${image_layers_field}.mLayers.iter_mut()
-                                  .zip(other.gecko.${image_layers_field}.mLayers.iter()) {
+                                  .zip(other.gecko.${image_layers_field}.mLayers.iter())
+                                  .take(count as usize) {
             layer.mPosition.m${orientation.upper()}Position
                 = other.mPosition.m${orientation.upper()}Position;
         }
-        self.gecko.${image_layers_field}.mPosition${orientation.upper()}Count
-               = other.gecko.${image_layers_field}.mPosition${orientation.upper()}Count;
+        self.gecko.${image_layers_field}.mPosition${orientation.upper()}Count = count;
     }
 
     pub fn clone_${shorthand}_position_${orientation}(&self)
         -> longhands::${shorthand}_position_${orientation}::computed_value::T {
         longhands::${shorthand}_position_${orientation}::computed_value::T(
             self.gecko.${image_layers_field}.mLayers.iter()
                 .take(self.gecko.${image_layers_field}.mPosition${orientation.upper()}Count as usize)
                 .map(|position| position.mPosition.m${orientation.upper()}Position.into())