servo: Merge #18761 - style: Iterate in the expected order in the custom_properties module (from emilio:custom-props-iter); r=SimonSapin
authorEmilio Cobos Álvarez <emilio@crisal.io>
Thu, 05 Oct 2017 09:22:24 -0500
changeset 384840 983f163e94eaf2022744e1135a43728d3ef6ef5d
parent 384839 534f2a0caa2c98d1eabb00e9a74352831bc2f2de
child 384841 0b06fec0239c467ffe76068c4b9f919e13583579
push id95880
push userarchaeopteryx@coole-files.de
push dateSat, 07 Oct 2017 08:58:44 +0000
treeherdermozilla-inbound@156942799371 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersSimonSapin
milestone58.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 #18761 - style: Iterate in the expected order in the custom_properties module (from emilio:custom-props-iter); r=SimonSapin In #18745, I replaced a few manual iterations over `index` with the iterator, and it changed the behavior of `layout/style/test/test_variables_order.html`, since it turns out that the iterator iterates right to left. I think this is just an accident that happened due to inconsistencies in how we were iterating over it, and that our behavior was inconsistent (since we iterated rtl in some cases, but ltr in others seems like it'd be inconsistent depending on the depth of the tree and different stuff). This brings back the expected behavior again, and ensures we iterate over a consistent order every time. Source-Repo: https://github.com/servo/servo Source-Revision: 00a2f55e5f39f8f077b83d43caf4710fa0647f76
servo/components/style/custom_properties.rs
--- a/servo/components/style/custom_properties.rs
+++ b/servo/components/style/custom_properties.rs
@@ -185,24 +185,24 @@ where
 
 impl<'a, K, V> Iterator for OrderedMapIterator<'a, K, V>
 where
     K: Eq + PrecomputedHash + Hash + Clone,
 {
     type Item = (&'a K, &'a V);
 
     fn next(&mut self) -> Option<Self::Item> {
-        let ref index = self.inner.index;
-        if self.pos >= index.len() {
-            return None;
-        }
+        let key = match self.inner.index.get(self.pos) {
+            Some(k) => k,
+            None => return None,
+        };
 
-        let ref key = index[index.len() - self.pos - 1];
         self.pos += 1;
         let value = &self.inner.values[key];
+
         Some((key, value))
     }
 }
 
 impl ComputedValue {
     fn empty() -> ComputedValue {
         ComputedValue {
             css: String::new(),