style: Fix origin iteration order. draft
authorCameron McCormack <cam@mcc.id.au>
Sat, 12 Aug 2017 17:38:06 +0800
changeset 645508 5d96bbf58c53e389b93bbe90e4ccdc87db55b8e7
parent 645507 93cbf10578e9ac3a436604ae4f7bc82a5b3adc9f
child 645509 7521a53080194e3c598638cd2cb68b8f00321b99
push id73769
push userbmo:cam@mcc.id.au
push dateSun, 13 Aug 2017 04:04:30 +0000
milestone57.0a1
style: Fix origin iteration order. MozReview-Commit-ID: 9WUUWXkog0c
servo/components/style/stylesheets/origin.rs
--- a/servo/components/style/stylesheets/origin.rs
+++ b/servo/components/style/stylesheets/origin.rs
@@ -11,70 +11,70 @@ use std::mem::transmute;
 ///
 /// https://drafts.csswg.org/css-cascade/#cascading-origins
 #[derive(Clone, PartialEq, Eq, Copy, Debug)]
 #[cfg_attr(feature = "servo", derive(HeapSizeOf))]
 pub enum Origin {
     /// https://drafts.csswg.org/css-cascade/#cascade-origin-us
     UserAgent,
 
+    /// https://drafts.csswg.org/css-cascade/#cascade-origin-user
+    User,
+
     /// https://drafts.csswg.org/css-cascade/#cascade-origin-author
     Author,
-
-    /// https://drafts.csswg.org/css-cascade/#cascade-origin-user
-    User,
 }
 
 /// An object that stores a `T` for each origin of the CSS cascade.
 #[cfg_attr(feature = "servo", derive(HeapSizeOf))]
 #[derive(Debug, Default)]
 pub struct PerOrigin<T> {
     /// Data for `Origin::UserAgent`.
     pub user_agent: T,
 
+    /// Data for `Origin::User`.
+    pub user: T,
+
     /// Data for `Origin::Author`.
     pub author: T,
-
-    /// Data for `Origin::User`.
-    pub user: T,
 }
 
 impl<T> PerOrigin<T> {
     /// Returns a reference to the per-origin data for the specified origin.
     #[inline]
     pub fn borrow_for_origin(&self, origin: &Origin) -> &T {
         match *origin {
             Origin::UserAgent => &self.user_agent,
+            Origin::User => &self.user,
             Origin::Author => &self.author,
-            Origin::User => &self.user,
         }
     }
 
     /// Returns a mutable reference to the per-origin data for the specified
     /// origin.
     #[inline]
     pub fn borrow_mut_for_origin(&mut self, origin: &Origin) -> &mut T {
         match *origin {
             Origin::UserAgent => &mut self.user_agent,
+            Origin::User => &mut self.user,
             Origin::Author => &mut self.author,
-            Origin::User => &mut self.user,
         }
     }
 
     /// Iterates over references to per-origin extra style data, from highest
-    /// level (user) to lowest (user agent).
+    /// level (author) to lowest (user agent).
     pub fn iter_origins(&self) -> PerOriginIter<T> {
         PerOriginIter {
             data: &self,
             cur: 0,
         }
     }
 
     /// Iterates over mutable references to per-origin extra style data, from
-    /// highest level (user) to lowest (user agent).
+    /// highest level (author) to lowest (user agent).
     pub fn iter_mut_origins(&mut self) -> PerOriginIterMut<T> {
         PerOriginIterMut {
             data: self,
             cur: 0,
             _marker: PhantomData,
         }
     }
 }
@@ -83,38 +83,38 @@ impl<T> PerOrigin<T> {
 pub trait PerOriginClear {
     /// Clears the object.
     fn clear(&mut self);
 }
 
 impl<T> PerOriginClear for PerOrigin<T> where T : PerOriginClear {
     fn clear(&mut self) {
         self.user_agent.clear();
+        self.user.clear();
         self.author.clear();
-        self.user.clear();
     }
 }
 
-/// Iterator over `PerOrigin<T>`, from highest level (user) to lowest
+/// Iterator over `PerOrigin<T>`, from highest level (author) to lowest
 /// (user agent).
 ///
 /// We rely on this specific order for correctly looking up @font-face,
 /// @counter-style and @keyframes rules.
 pub struct PerOriginIter<'a, T: 'a> {
     data: &'a PerOrigin<T>,
     cur: usize,
 }
 
 impl<'a, T> Iterator for PerOriginIter<'a, T> where T: 'a {
     type Item = (&'a T, Origin);
 
     fn next(&mut self) -> Option<Self::Item> {
         let result = match self.cur {
-            0 => (&self.data.user, Origin::User),
-            1 => (&self.data.author, Origin::Author),
+            0 => (&self.data.author, Origin::Author),
+            1 => (&self.data.user, Origin::User),
             2 => (&self.data.user_agent, Origin::UserAgent),
             _ => return None,
         };
         self.cur += 1;
         Some(result)
     }
 }
 
@@ -130,17 +130,17 @@ pub struct PerOriginIterMut<'a, T: 'a> {
     _marker: PhantomData<&'a mut PerOrigin<T>>,
 }
 
 impl<'a, T> Iterator for PerOriginIterMut<'a, T> where T: 'a {
     type Item = (&'a mut T, Origin);
 
     fn next(&mut self) -> Option<Self::Item> {
         let result = match self.cur {
-            0 => (unsafe { transmute(&mut (*self.data).user) }, Origin::User),
-            1 => (unsafe { transmute(&mut (*self.data).author) }, Origin::Author),
+            0 => (unsafe { transmute(&mut (*self.data).author) }, Origin::Author),
+            1 => (unsafe { transmute(&mut (*self.data).user) }, Origin::User),
             2 => (unsafe { transmute(&mut (*self.data).user_agent) }, Origin::UserAgent),
             _ => return None,
         };
         self.cur += 1;
         Some(result)
     }
 }