Change ToNsCssValue to take the ownership of value. r?SimonSapin draft
authorXidorn Quan <me@upsuper.org>
Wed, 10 May 2017 10:44:58 +1000
changeset 577630 fe0a12a13f35956d4ead502778ac2fbc77264940
parent 577629 0fb67f6606718b2efc177c9fcb3a86a07bbf203b
child 577631 a7c0971b77dd25af6e8c68b5133f01376681d548
push id58742
push userxquan@mozilla.com
push dateMon, 15 May 2017 05:03:58 +0000
reviewersSimonSapin
milestone55.0a1
Change ToNsCssValue to take the ownership of value. r?SimonSapin MozReview-Commit-ID: 3HdEjNDhVRh
servo/components/style/counter_style/mod.rs
servo/components/style/font_face.rs
servo/components/style/gecko/rules.rs
servo/components/style/gecko_bindings/sugar/ns_css_value.rs
--- a/servo/components/style/counter_style/mod.rs
+++ b/servo/components/style/counter_style/mod.rs
@@ -167,19 +167,19 @@ macro_rules! counter_style_descriptors {
             }
 
             $(
                 accessor!(#[$doc] $name $ident: $ty = $initial);
             )+
 
             /// Convert to Gecko types
             #[cfg(feature = "gecko")]
-            pub fn set_descriptors(&self, descriptors: &mut CounterStyleDescriptors) {
+            pub fn set_descriptors(self, descriptors: &mut CounterStyleDescriptors) {
                 $(
-                    if let Some(ref value) = self.$ident {
+                    if let Some(value) = self.$ident {
                         descriptors[nsCSSCounterDesc::$gecko_ident as usize].set_from(value)
                     }
                 )*
             }
         }
 
        impl<'a, 'b> DeclarationParser for CounterStyleRuleParser<'a, 'b> {
             type Declaration = ();
--- a/servo/components/style/font_face.rs
+++ b/servo/components/style/font_face.rs
@@ -194,19 +194,19 @@ macro_rules! font_face_descriptors_commo
                     $(
                         $ident: None,
                     )*
                 }
             }
 
             /// Convert to Gecko types
             #[cfg(feature = "gecko")]
-            pub fn set_descriptors(&self, descriptors: &mut CSSFontFaceDescriptors) {
+            pub fn set_descriptors(self, descriptors: &mut CSSFontFaceDescriptors) {
                 $(
-                    if let Some(ref value) = self.$ident {
+                    if let Some(value) = self.$ident {
                         descriptors.$gecko_ident.set_from(value)
                     }
                 )*
                 // Leave unset descriptors to eCSSUnit_Null,
                 // FontFaceSet::FindOrCreateUserFontEntryFromFontFace does the defaulting
                 // to initial values.
             }
         }
--- a/servo/components/style/gecko/rules.rs
+++ b/servo/components/style/gecko/rules.rs
@@ -16,39 +16,39 @@ use gecko_bindings::sugar::ns_css_value:
 use gecko_bindings::sugar::refptr::{RefPtr, UniqueRefPtr};
 use shared_lock::{ToCssWithGuard, SharedRwLockReadGuard};
 use std::fmt;
 
 /// A @font-face rule
 pub type FontFaceRule = RefPtr<nsCSSFontFaceRule>;
 
 impl ToNsCssValue for FamilyName {
-    fn convert(&self, nscssvalue: &mut nsCSSValue) {
+    fn convert(self, nscssvalue: &mut nsCSSValue) {
         nscssvalue.set_string_from_atom(&self.name)
     }
 }
 
 impl ToNsCssValue for font_weight::T {
-    fn convert(&self, nscssvalue: &mut nsCSSValue) {
-        nscssvalue.set_integer(*self as i32)
+    fn convert(self, nscssvalue: &mut nsCSSValue) {
+        nscssvalue.set_integer(self as i32)
     }
 }
 
 macro_rules! map_enum {
     (
         $(
             $prop:ident {
                 $($servo:ident => $gecko:ident,)+
             }
         )+
     ) => {
         $(
             impl ToNsCssValue for $prop::T {
-                fn convert(&self, nscssvalue: &mut nsCSSValue) {
-                    nscssvalue.set_enum(match *self {
+                fn convert(self, nscssvalue: &mut nsCSSValue) {
+                    nscssvalue.set_enum(match self {
                         $( $prop::T::$servo => structs::$gecko as i32, )+
                     })
                 }
             }
         )+
     }
 }
 
@@ -68,48 +68,48 @@ map_enum! {
         semi_expanded   => NS_FONT_STRETCH_SEMI_EXPANDED,
         expanded        => NS_FONT_STRETCH_EXPANDED,
         extra_expanded  => NS_FONT_STRETCH_EXTRA_EXPANDED,
         ultra_expanded  => NS_FONT_STRETCH_ULTRA_EXPANDED,
     }
 }
 
 impl ToNsCssValue for Vec<Source> {
-    fn convert(&self, nscssvalue: &mut nsCSSValue) {
+    fn convert(self, nscssvalue: &mut nsCSSValue) {
         let src_len = self.iter().fold(0, |acc, src| {
             acc + match *src {
                 // Each format hint takes one position in the array of mSrc.
                 Source::Url(ref url) => url.format_hints.len() + 1,
                 Source::Local(_) => 1,
             }
         });
         let mut target_srcs =
             nscssvalue.set_array(src_len as i32).as_mut_slice().iter_mut();
         macro_rules! next { () => {
             target_srcs.next().expect("Length of target_srcs should be enough")
         } }
-        for src in self.iter() {
-            match *src {
-                Source::Url(ref url) => {
+        for src in self.into_iter() {
+            match src {
+                Source::Url(url) => {
                     next!().set_url(&url.url);
                     for hint in url.format_hints.iter() {
                         next!().set_font_format(&hint);
                     }
                 }
-                Source::Local(ref family) => {
+                Source::Local(family) => {
                     next!().set_local_font(&family.name);
                 }
             }
         }
         debug_assert!(target_srcs.next().is_none(), "Should have filled all slots");
     }
 }
 
 impl ToNsCssValue for Vec<UnicodeRange> {
-    fn convert(&self, nscssvalue: &mut nsCSSValue) {
+    fn convert(self, nscssvalue: &mut nsCSSValue) {
         let target_ranges = nscssvalue
             .set_array((self.len() * 2) as i32)
             .as_mut_slice().chunks_mut(2);
         for (range, target) in self.iter().zip(target_ranges) {
             target[0].set_integer(range.start as i32);
             target[1].set_integer(range.end as i32);
         }
     }
@@ -160,71 +160,71 @@ impl ToCssWithGuard for CounterStyleRule
         write!(dest, "{}", css_text)
     }
 }
 
 /// The type of nsCSSCounterStyleRule::mValues
 pub type CounterStyleDescriptors = [nsCSSValue; nsCSSCounterDesc::eCSSCounterDesc_COUNT as usize];
 
 impl ToNsCssValue for counter_style::System {
-    fn convert(&self, nscssvalue: &mut nsCSSValue) {
+    fn convert(self, nscssvalue: &mut nsCSSValue) {
         use counter_style::System::*;
-        match *self {
+        match self {
             Cyclic => nscssvalue.set_enum(structs::NS_STYLE_COUNTER_SYSTEM_CYCLIC as i32),
             Numeric => nscssvalue.set_enum(structs::NS_STYLE_COUNTER_SYSTEM_NUMERIC as i32),
             Alphabetic => nscssvalue.set_enum(structs::NS_STYLE_COUNTER_SYSTEM_ALPHABETIC as i32),
             Symbolic => nscssvalue.set_enum(structs::NS_STYLE_COUNTER_SYSTEM_SYMBOLIC as i32),
             Additive => nscssvalue.set_enum(structs::NS_STYLE_COUNTER_SYSTEM_ADDITIVE as i32),
             Fixed { first_symbol_value } => {
                 let mut a = nsCSSValue::null();
                 let mut b = nsCSSValue::null();
                 a.set_enum(structs::NS_STYLE_COUNTER_SYSTEM_FIXED as i32);
                 b.set_integer(first_symbol_value.unwrap_or(1));
                 nscssvalue.set_pair(&a, &b);
             }
-            Extends(ref other) => {
+            Extends(other) => {
                 let mut a = nsCSSValue::null();
                 let mut b = nsCSSValue::null();
                 a.set_enum(structs::NS_STYLE_COUNTER_SYSTEM_EXTENDS as i32);
                 b.set_string_from_atom(&other.0);
                 nscssvalue.set_pair(&a, &b);
             }
         }
     }
 }
 
 impl ToNsCssValue for counter_style::Negative {
-    fn convert(&self, nscssvalue: &mut nsCSSValue) {
-        if let Some(ref second) = self.1 {
+    fn convert(self, nscssvalue: &mut nsCSSValue) {
+        if let Some(second) = self.1 {
             let mut a = nsCSSValue::null();
             let mut b = nsCSSValue::null();
-            a.set_from(&self.0);
+            a.set_from(self.0);
             b.set_from(second);
             nscssvalue.set_pair(&a, &b);
         } else {
-            nscssvalue.set_from(&self.0)
+            nscssvalue.set_from(self.0)
         }
     }
 }
 
 impl ToNsCssValue for counter_style::Symbol {
-    fn convert(&self, nscssvalue: &mut nsCSSValue) {
-        match *self {
-            counter_style::Symbol::String(ref s) => nscssvalue.set_string(s),
-            counter_style::Symbol::Ident(ref s) => nscssvalue.set_ident(s),
+    fn convert(self, nscssvalue: &mut nsCSSValue) {
+        match self {
+            counter_style::Symbol::String(s) => nscssvalue.set_string(&s),
+            counter_style::Symbol::Ident(s) => nscssvalue.set_ident(&s),
         }
     }
 }
 
 impl ToNsCssValue for counter_style::Ranges {
-    fn convert(&self, nscssvalue: &mut nsCSSValue) {
+    fn convert(self, nscssvalue: &mut nsCSSValue) {
         if self.0.is_empty() {
             nscssvalue.set_auto();
         } else {
-            nscssvalue.set_pair_list(self.0.iter().map(|range| {
+            nscssvalue.set_pair_list(self.0.into_iter().map(|range| {
                 fn set_bound(bound: Option<i32>, nscssvalue: &mut nsCSSValue) {
                     if let Some(finite) = bound {
                         nscssvalue.set_integer(finite)
                     } else {
                         nscssvalue.set_enum(structs::NS_STYLE_COUNTER_RANGE_INFINITE as i32)
                     }
                 }
                 let mut start = nsCSSValue::null();
@@ -233,57 +233,57 @@ impl ToNsCssValue for counter_style::Ran
                 set_bound(range.end, &mut end);
                 (start, end)
             }));
         }
     }
 }
 
 impl ToNsCssValue for counter_style::Pad {
-    fn convert(&self, nscssvalue: &mut nsCSSValue) {
+    fn convert(self, nscssvalue: &mut nsCSSValue) {
         let mut min_length = nsCSSValue::null();
         let mut pad_with = nsCSSValue::null();
         min_length.set_integer(self.0 as i32);
-        pad_with.set_from(&self.1);
+        pad_with.set_from(self.1);
         nscssvalue.set_pair(&min_length, &pad_with);
     }
 }
 
 impl ToNsCssValue for counter_style::Fallback {
-    fn convert(&self, nscssvalue: &mut nsCSSValue) {
+    fn convert(self, nscssvalue: &mut nsCSSValue) {
         nscssvalue.set_ident_from_atom(&self.0 .0)
     }
 }
 
 impl ToNsCssValue for counter_style::Symbols {
-    fn convert(&self, nscssvalue: &mut nsCSSValue) {
-        nscssvalue.set_list(self.0.iter().map(|item| {
+    fn convert(self, nscssvalue: &mut nsCSSValue) {
+        nscssvalue.set_list(self.0.into_iter().map(|item| {
             let mut value = nsCSSValue::null();
             value.set_from(item);
             value
         }));
     }
 }
 
 impl ToNsCssValue for counter_style::AdditiveSymbols {
-    fn convert(&self, nscssvalue: &mut nsCSSValue) {
-        nscssvalue.set_pair_list(self.0.iter().map(|tuple| {
+    fn convert(self, nscssvalue: &mut nsCSSValue) {
+        nscssvalue.set_pair_list(self.0.into_iter().map(|tuple| {
             let mut weight = nsCSSValue::null();
             let mut symbol = nsCSSValue::null();
             weight.set_integer(tuple.weight as i32);
-            symbol.set_from(&tuple.symbol);
+            symbol.set_from(tuple.symbol);
             (weight, symbol)
         }));
     }
 }
 
 impl ToNsCssValue for counter_style::SpeakAs {
-    fn convert(&self, nscssvalue: &mut nsCSSValue) {
+    fn convert(self, nscssvalue: &mut nsCSSValue) {
         use counter_style::SpeakAs::*;
-        match *self {
+        match self {
             Auto => nscssvalue.set_auto(),
             Bullets => nscssvalue.set_enum(structs::NS_STYLE_COUNTER_SPEAKAS_BULLETS as i32),
             Numbers => nscssvalue.set_enum(structs::NS_STYLE_COUNTER_SPEAKAS_NUMBERS as i32),
             Words => nscssvalue.set_enum(structs::NS_STYLE_COUNTER_SPEAKAS_WORDS as i32),
-            Other(ref other) => nscssvalue.set_ident_from_atom(&other.0),
+            Other(other) => nscssvalue.set_ident_from_atom(&other.0),
         }
     }
 }
--- a/servo/components/style/gecko_bindings/sugar/ns_css_value.rs
+++ b/servo/components/style/gecko_bindings/sugar/ns_css_value.rs
@@ -186,17 +186,17 @@ impl nsCSSValue {
 
     /// Set to an array of given length
     pub fn set_array(&mut self, len: i32) -> &mut nsCSSValue_Array {
         unsafe { bindings::Gecko_CSSValue_SetArray(self, len) }
         unsafe { self.mValue.mArray.as_mut().as_mut() }.unwrap()
     }
 
     /// Generic set from any value that implements the ToNsCssValue trait.
-    pub fn set_from<T: ToNsCssValue>(&mut self, value: &T) {
+    pub fn set_from<T: ToNsCssValue>(&mut self, value: T) {
         value.convert(self)
     }
 
     /// Returns an `Angle` value from this `nsCSSValue`.
     ///
     /// Panics if the unit is not `eCSSUnit_Degree` `eCSSUnit_Grad`, `eCSSUnit_Turn`
     /// or `eCSSUnit_Radian`.
     pub fn get_angle(&self) -> Angle {
@@ -306,10 +306,10 @@ impl IndexMut<usize> for nsCSSValue_Arra
     fn index_mut(&mut self, i: usize) -> &mut nsCSSValue {
         &mut self.as_mut_slice()[i]
     }
 }
 
 /// Generic conversion to nsCSSValue
 pub trait ToNsCssValue {
     /// Convert
-    fn convert(&self, nscssvalue: &mut nsCSSValue);
+    fn convert(self, nscssvalue: &mut nsCSSValue);
 }