diff --git a/src/libserialize/collection_impls.rs b/src/libserialize/collection_impls.rs index 7103e1c7919..9748a506392 100644 --- a/src/libserialize/collection_impls.rs +++ b/src/libserialize/collection_impls.rs @@ -17,10 +17,7 @@ use std::collections::{LinkedList, VecDeque, BTreeMap, BTreeSet, HashMap, HashSe use std::rc::Rc; use std::sync::Arc; -impl< - T: Encodable -> Encodable for LinkedList { - #[inline] +impl Encodable for LinkedList { fn encode(&self, s: &mut S) -> Result<(), S::Error> { s.emit_seq(self.len(), |s| { for (i, e) in self.iter().enumerate() { @@ -32,7 +29,6 @@ impl< } impl Decodable for LinkedList { - #[inline] fn decode(d: &mut D) -> Result, D::Error> { d.read_seq(|d, len| { let mut list = LinkedList::new(); @@ -45,7 +41,6 @@ impl Decodable for LinkedList { } impl Encodable for VecDeque { - #[inline] fn encode(&self, s: &mut S) -> Result<(), S::Error> { s.emit_seq(self.len(), |s| { for (i, e) in self.iter().enumerate() { @@ -57,7 +52,6 @@ impl Encodable for VecDeque { } impl Decodable for VecDeque { - #[inline] fn decode(d: &mut D) -> Result, D::Error> { d.read_seq(|d, len| { let mut deque: VecDeque = VecDeque::new(); @@ -69,11 +63,10 @@ impl Decodable for VecDeque { } } -impl< - K: Encodable + PartialEq + Ord, - V: Encodable -> Encodable for BTreeMap { - #[inline] +impl Encodable for BTreeMap + where K: Encodable + PartialEq + Ord, + V: Encodable +{ fn encode(&self, e: &mut S) -> Result<(), S::Error> { e.emit_map(self.len(), |e| { let mut i = 0; @@ -87,11 +80,10 @@ impl< } } -impl< - K: Decodable + PartialEq + Ord, - V: Decodable -> Decodable for BTreeMap { - #[inline] +impl Decodable for BTreeMap + where K: Decodable + PartialEq + Ord, + V: Decodable +{ fn decode(d: &mut D) -> Result, D::Error> { d.read_map(|d, len| { let mut map = BTreeMap::new(); @@ -105,10 +97,9 @@ impl< } } -impl< - T: Encodable + PartialEq + Ord -> Encodable for BTreeSet { - #[inline] +impl Encodable for BTreeSet + where T: Encodable + PartialEq + Ord +{ fn encode(&self, s: &mut S) -> Result<(), S::Error> { s.emit_seq(self.len(), |s| { let mut i = 0; @@ -121,10 +112,9 @@ impl< } } -impl< - T: Decodable + PartialEq + Ord -> Decodable for BTreeSet { - #[inline] +impl Decodable for BTreeSet + where T: Decodable + PartialEq + Ord +{ fn decode(d: &mut D) -> Result, D::Error> { d.read_seq(|d, len| { let mut set = BTreeSet::new(); @@ -141,7 +131,6 @@ impl Encodable for HashMap V: Encodable, S: BuildHasher, { - #[inline] fn encode(&self, e: &mut E) -> Result<(), E::Error> { e.emit_map(self.len(), |e| { let mut i = 0; @@ -160,7 +149,6 @@ impl Decodable for HashMap V: Decodable, S: BuildHasher + Default, { - #[inline] fn decode(d: &mut D) -> Result, D::Error> { d.read_map(|d, len| { let state = Default::default(); @@ -179,7 +167,6 @@ impl Encodable for HashSet where T: Encodable + Hash + Eq, S: BuildHasher, { - #[inline] fn encode(&self, s: &mut E) -> Result<(), E::Error> { s.emit_seq(self.len(), |s| { let mut i = 0; @@ -196,7 +183,6 @@ impl Decodable for HashSet where T: Decodable + Hash + Eq, S: BuildHasher + Default, { - #[inline] fn decode(d: &mut D) -> Result, D::Error> { d.read_seq(|d, len| { let state = Default::default(); @@ -210,7 +196,6 @@ impl Decodable for HashSet } impl Encodable for Rc<[T]> { - #[inline] fn encode(&self, s: &mut E) -> Result<(), E::Error> { s.emit_seq(self.len(), |s| { for (index, e) in self.iter().enumerate() { @@ -222,7 +207,6 @@ impl Encodable for Rc<[T]> { } impl Decodable for Rc<[T]> { - #[inline] fn decode(d: &mut D) -> Result, D::Error> { d.read_seq(|d, len| { let mut vec = Vec::with_capacity(len); @@ -235,7 +219,6 @@ impl Decodable for Rc<[T]> { } impl Encodable for Arc<[T]> { - #[inline] fn encode(&self, s: &mut E) -> Result<(), E::Error> { s.emit_seq(self.len(), |s| { for (index, e) in self.iter().enumerate() { @@ -247,7 +230,6 @@ impl Encodable for Arc<[T]> { } impl Decodable for Arc<[T]> { - #[inline] fn decode(d: &mut D) -> Result, D::Error> { d.read_seq(|d, len| { let mut vec = Vec::with_capacity(len); diff --git a/src/libserialize/serialize.rs b/src/libserialize/serialize.rs index b2073f6d0a3..60bb5a0fec2 100644 --- a/src/libserialize/serialize.rs +++ b/src/libserialize/serialize.rs @@ -45,14 +45,12 @@ pub trait Encoder { fn emit_str(&mut self, v: &str) -> Result<(), Self::Error>; // Compound types: - #[inline] fn emit_enum(&mut self, _name: &str, f: F) -> Result<(), Self::Error> where F: FnOnce(&mut Self) -> Result<(), Self::Error> { f(self) } - #[inline] fn emit_enum_variant(&mut self, _v_name: &str, v_id: usize, _len: usize, f: F) -> Result<(), Self::Error> where F: FnOnce(&mut Self) -> Result<(), Self::Error> { @@ -60,63 +58,54 @@ pub trait Encoder { f(self) } - #[inline] fn emit_enum_variant_arg(&mut self, _a_idx: usize, f: F) -> Result<(), Self::Error> where F: FnOnce(&mut Self) -> Result<(), Self::Error> { f(self) } - #[inline] fn emit_enum_struct_variant(&mut self, v_name: &str, v_id: usize, len: usize, f: F) -> Result<(), Self::Error> where F: FnOnce(&mut Self) -> Result<(), Self::Error> { self.emit_enum_variant(v_name, v_id, len, f) } - #[inline] fn emit_enum_struct_variant_field(&mut self, _f_name: &str, f_idx: usize, f: F) -> Result<(), Self::Error> where F: FnOnce(&mut Self) -> Result<(), Self::Error> { self.emit_enum_variant_arg(f_idx, f) } - #[inline] fn emit_struct(&mut self, _name: &str, _len: usize, f: F) -> Result<(), Self::Error> where F: FnOnce(&mut Self) -> Result<(), Self::Error> { f(self) } - #[inline] fn emit_struct_field(&mut self, _f_name: &str, _f_idx: usize, f: F) -> Result<(), Self::Error> where F: FnOnce(&mut Self) -> Result<(), Self::Error> { f(self) } - #[inline] fn emit_tuple(&mut self, _len: usize, f: F) -> Result<(), Self::Error> where F: FnOnce(&mut Self) -> Result<(), Self::Error> { f(self) } - #[inline] fn emit_tuple_arg(&mut self, _idx: usize, f: F) -> Result<(), Self::Error> where F: FnOnce(&mut Self) -> Result<(), Self::Error> { f(self) } - #[inline] fn emit_tuple_struct(&mut self, _name: &str, len: usize, f: F) -> Result<(), Self::Error> where F: FnOnce(&mut Self) -> Result<(), Self::Error> { self.emit_tuple(len, f) } - #[inline] fn emit_tuple_struct_arg(&mut self, f_idx: usize, f: F) -> Result<(), Self::Error> where F: FnOnce(&mut Self) -> Result<(), Self::Error> { @@ -124,7 +113,6 @@ pub trait Encoder { } // Specialized types: - #[inline] fn emit_option(&mut self, f: F) -> Result<(), Self::Error> where F: FnOnce(&mut Self) -> Result<(), Self::Error> { @@ -136,14 +124,12 @@ pub trait Encoder { self.emit_enum_variant("None", 0, 0, |_| Ok(())) } - #[inline] fn emit_option_some(&mut self, f: F) -> Result<(), Self::Error> where F: FnOnce(&mut Self) -> Result<(), Self::Error> { self.emit_enum_variant("Some", 1, 1, f) } - #[inline] fn emit_seq(&mut self, len: usize, f: F) -> Result<(), Self::Error> where F: FnOnce(&mut Self) -> Result<(), Self::Error> { @@ -151,14 +137,12 @@ pub trait Encoder { f(self) } - #[inline] fn emit_seq_elt(&mut self, _idx: usize, f: F) -> Result<(), Self::Error> where F: FnOnce(&mut Self) -> Result<(), Self::Error> { f(self) } - #[inline] fn emit_map(&mut self, len: usize, f: F) -> Result<(), Self::Error> where F: FnOnce(&mut Self) -> Result<(), Self::Error> { @@ -166,14 +150,12 @@ pub trait Encoder { f(self) } - #[inline] fn emit_map_elt_key(&mut self, _idx: usize, f: F) -> Result<(), Self::Error> where F: FnOnce(&mut Self) -> Result<(), Self::Error> { f(self) } - #[inline] fn emit_map_elt_val(&mut self, _idx: usize, f: F) -> Result<(), Self::Error> where F: FnOnce(&mut Self) -> Result<(), Self::Error> { @@ -205,14 +187,12 @@ pub trait Decoder { fn read_str(&mut self) -> Result, Self::Error>; // Compound types: - #[inline] fn read_enum(&mut self, _name: &str, f: F) -> Result where F: FnOnce(&mut Self) -> Result { f(self) } - #[inline] fn read_enum_variant(&mut self, _names: &[&str], mut f: F) -> Result where F: FnMut(&mut Self, usize) -> Result { @@ -220,63 +200,54 @@ pub trait Decoder { f(self, disr) } - #[inline] fn read_enum_variant_arg(&mut self, _a_idx: usize, f: F) -> Result where F: FnOnce(&mut Self) -> Result { f(self) } - #[inline] fn read_enum_struct_variant(&mut self, names: &[&str], f: F) -> Result where F: FnMut(&mut Self, usize) -> Result { self.read_enum_variant(names, f) } - #[inline] fn read_enum_struct_variant_field(&mut self, _f_name: &str, f_idx: usize, f: F) -> Result where F: FnOnce(&mut Self) -> Result { self.read_enum_variant_arg(f_idx, f) } - #[inline] fn read_struct(&mut self, _s_name: &str, _len: usize, f: F) -> Result where F: FnOnce(&mut Self) -> Result { f(self) } - #[inline] fn read_struct_field(&mut self, _f_name: &str, _f_idx: usize, f: F) -> Result where F: FnOnce(&mut Self) -> Result { f(self) } - #[inline] fn read_tuple(&mut self, _len: usize, f: F) -> Result where F: FnOnce(&mut Self) -> Result { f(self) } - #[inline] fn read_tuple_arg(&mut self, _a_idx: usize, f: F) -> Result where F: FnOnce(&mut Self) -> Result { f(self) } - #[inline] fn read_tuple_struct(&mut self, _s_name: &str, len: usize, f: F) -> Result where F: FnOnce(&mut Self) -> Result { self.read_tuple(len, f) } - #[inline] fn read_tuple_struct_arg(&mut self, a_idx: usize, f: F) -> Result where F: FnOnce(&mut Self) -> Result { @@ -284,7 +255,6 @@ pub trait Decoder { } // Specialized types: - #[inline] fn read_option(&mut self, mut f: F) -> Result where F: FnMut(&mut Self, bool) -> Result { @@ -299,7 +269,6 @@ pub trait Decoder { }) } - #[inline] fn read_seq(&mut self, f: F) -> Result where F: FnOnce(&mut Self, usize) -> Result { @@ -307,14 +276,12 @@ pub trait Decoder { f(self, len) } - #[inline] fn read_seq_elt(&mut self, _idx: usize, f: F) -> Result where F: FnOnce(&mut Self) -> Result { f(self) } - #[inline] fn read_map(&mut self, f: F) -> Result where F: FnOnce(&mut Self, usize) -> Result { @@ -322,14 +289,12 @@ pub trait Decoder { f(self, len) } - #[inline] fn read_map_elt_key(&mut self, _idx: usize, f: F) -> Result where F: FnOnce(&mut Self) -> Result { f(self) } - #[inline] fn read_map_elt_val(&mut self, _idx: usize, f: F) -> Result where F: FnOnce(&mut Self) -> Result { @@ -349,287 +314,246 @@ pub trait Decodable: Sized { } impl Encodable for usize { - #[inline] fn encode(&self, s: &mut S) -> Result<(), S::Error> { s.emit_usize(*self) } } impl Decodable for usize { - #[inline] fn decode(d: &mut D) -> Result { d.read_usize() } } impl Encodable for u8 { - #[inline] fn encode(&self, s: &mut S) -> Result<(), S::Error> { s.emit_u8(*self) } } impl Decodable for u8 { - #[inline] fn decode(d: &mut D) -> Result { d.read_u8() } } impl Encodable for u16 { - #[inline] fn encode(&self, s: &mut S) -> Result<(), S::Error> { s.emit_u16(*self) } } impl Decodable for u16 { - #[inline] fn decode(d: &mut D) -> Result { d.read_u16() } } impl Encodable for u32 { - #[inline] fn encode(&self, s: &mut S) -> Result<(), S::Error> { s.emit_u32(*self) } } impl Decodable for u32 { - #[inline] fn decode(d: &mut D) -> Result { d.read_u32() } } impl Encodable for u64 { - #[inline] fn encode(&self, s: &mut S) -> Result<(), S::Error> { s.emit_u64(*self) } } impl Decodable for u64 { - #[inline] fn decode(d: &mut D) -> Result { d.read_u64() } } impl Encodable for u128 { - #[inline] fn encode(&self, s: &mut S) -> Result<(), S::Error> { s.emit_u128(*self) } } impl Decodable for u128 { - #[inline] fn decode(d: &mut D) -> Result { d.read_u128() } } impl Encodable for isize { - #[inline] fn encode(&self, s: &mut S) -> Result<(), S::Error> { s.emit_isize(*self) } } impl Decodable for isize { - #[inline] fn decode(d: &mut D) -> Result { d.read_isize() } } impl Encodable for i8 { - #[inline] fn encode(&self, s: &mut S) -> Result<(), S::Error> { s.emit_i8(*self) } } impl Decodable for i8 { - #[inline] fn decode(d: &mut D) -> Result { d.read_i8() } } impl Encodable for i16 { - #[inline] fn encode(&self, s: &mut S) -> Result<(), S::Error> { s.emit_i16(*self) } } impl Decodable for i16 { - #[inline] fn decode(d: &mut D) -> Result { d.read_i16() } } impl Encodable for i32 { - #[inline] fn encode(&self, s: &mut S) -> Result<(), S::Error> { s.emit_i32(*self) } } impl Decodable for i32 { - #[inline] fn decode(d: &mut D) -> Result { d.read_i32() } } impl Encodable for i64 { - #[inline] fn encode(&self, s: &mut S) -> Result<(), S::Error> { s.emit_i64(*self) } } impl Decodable for i64 { - #[inline] fn decode(d: &mut D) -> Result { d.read_i64() } } impl Encodable for i128 { - #[inline] fn encode(&self, s: &mut S) -> Result<(), S::Error> { s.emit_i128(*self) } } impl Decodable for i128 { - #[inline] fn decode(d: &mut D) -> Result { d.read_i128() } } impl Encodable for str { - #[inline] fn encode(&self, s: &mut S) -> Result<(), S::Error> { s.emit_str(self) } } impl Encodable for String { - #[inline] fn encode(&self, s: &mut S) -> Result<(), S::Error> { s.emit_str(&self[..]) } } impl Decodable for String { - #[inline] fn decode(d: &mut D) -> Result { Ok(d.read_str()?.into_owned()) } } impl Encodable for f32 { - #[inline] fn encode(&self, s: &mut S) -> Result<(), S::Error> { s.emit_f32(*self) } } impl Decodable for f32 { - #[inline] fn decode(d: &mut D) -> Result { d.read_f32() } } impl Encodable for f64 { - #[inline] fn encode(&self, s: &mut S) -> Result<(), S::Error> { s.emit_f64(*self) } } impl Decodable for f64 { - #[inline] fn decode(d: &mut D) -> Result { d.read_f64() } } impl Encodable for bool { - #[inline] fn encode(&self, s: &mut S) -> Result<(), S::Error> { s.emit_bool(*self) } } impl Decodable for bool { - #[inline] fn decode(d: &mut D) -> Result { d.read_bool() } } impl Encodable for char { - #[inline] fn encode(&self, s: &mut S) -> Result<(), S::Error> { s.emit_char(*self) } } impl Decodable for char { - #[inline] fn decode(d: &mut D) -> Result { d.read_char() } } impl Encodable for () { - #[inline] fn encode(&self, s: &mut S) -> Result<(), S::Error> { s.emit_nil() } } impl Decodable for () { - #[inline] fn decode(d: &mut D) -> Result<(), D::Error> { d.read_nil() } } impl<'a, T: ?Sized + Encodable> Encodable for &'a T { - #[inline] fn encode(&self, s: &mut S) -> Result<(), S::Error> { (**self).encode(s) } } impl Encodable for Box { - #[inline] fn encode(&self, s: &mut S) -> Result<(), S::Error> { (**self).encode(s) } } impl< T: Decodable> Decodable for Box { - #[inline] fn decode(d: &mut D) -> Result, D::Error> { Ok(box Decodable::decode(d)?) } } impl< T: Decodable> Decodable for Box<[T]> { - #[inline] fn decode(d: &mut D) -> Result, D::Error> { let v: Vec = Decodable::decode(d)?; Ok(v.into_boxed_slice()) @@ -637,21 +561,18 @@ impl< T: Decodable> Decodable for Box<[T]> { } impl Encodable for Rc { - #[inline] fn encode(&self, s: &mut S) -> Result<(), S::Error> { (**self).encode(s) } } impl Decodable for Rc { - #[inline] fn decode(d: &mut D) -> Result, D::Error> { Ok(Rc::new(Decodable::decode(d)?)) } } impl Encodable for [T] { - #[inline] fn encode(&self, s: &mut S) -> Result<(), S::Error> { s.emit_seq(self.len(), |s| { for (i, e) in self.iter().enumerate() { @@ -663,7 +584,6 @@ impl Encodable for [T] { } impl Encodable for Vec { - #[inline] fn encode(&self, s: &mut S) -> Result<(), S::Error> { s.emit_seq(self.len(), |s| { for (i, e) in self.iter().enumerate() { @@ -675,7 +595,6 @@ impl Encodable for Vec { } impl Decodable for Vec { - #[inline] fn decode(d: &mut D) -> Result, D::Error> { d.read_seq(|d, len| { let mut v = Vec::with_capacity(len); @@ -688,7 +607,6 @@ impl Decodable for Vec { } impl<'a, T:Encodable> Encodable for Cow<'a, [T]> where [T]: ToOwned> { - #[inline] fn encode(&self, s: &mut S) -> Result<(), S::Error> { s.emit_seq(self.len(), |s| { for (i, e) in self.iter().enumerate() { @@ -699,8 +617,9 @@ impl<'a, T:Encodable> Encodable for Cow<'a, [T]> where [T]: ToOwned Decodable for Cow<'static, [T]> where [T]: ToOwned> { - #[inline] +impl Decodable for Cow<'static, [T]> + where [T]: ToOwned> +{ fn decode(d: &mut D) -> Result, D::Error> { d.read_seq(|d, len| { let mut v = Vec::with_capacity(len); @@ -714,7 +633,6 @@ impl Decodable for Cow<'static, [T]> where [T]: ToOwned Encodable for Option { - #[inline] fn encode(&self, s: &mut S) -> Result<(), S::Error> { s.emit_option(|s| { match *self { @@ -726,7 +644,6 @@ impl Encodable for Option { } impl Decodable for Option { - #[inline] fn decode(d: &mut D) -> Result, D::Error> { d.read_option(|d, b| { if b { @@ -739,7 +656,6 @@ impl Decodable for Option { } impl Encodable for Result { - #[inline] fn encode(&self, s: &mut S) -> Result<(), S::Error> { s.emit_enum("Result", |s| { match *self { @@ -763,7 +679,6 @@ impl Encodable for Result { } impl Decodable for Result { - #[inline] fn decode(d: &mut D) -> Result, D::Error> { d.read_enum("Result", |d| { d.read_enum_variant(&["Ok", "Err"], |d, disr| { @@ -803,7 +718,6 @@ macro_rules! tuple { ( $($name:ident,)+ ) => ( impl<$($name:Decodable),*> Decodable for ($($name,)*) { #[allow(non_snake_case)] - #[inline] fn decode(d: &mut D) -> Result<($($name,)*), D::Error> { let len: usize = count_idents!($($name,)*); d.read_tuple(len, |d| { @@ -817,7 +731,6 @@ macro_rules! tuple { } impl<$($name:Encodable),*> Encodable for ($($name,)*) { #[allow(non_snake_case)] - #[inline] fn encode(&self, s: &mut S) -> Result<(), S::Error> { let ($(ref $name,)*) = *self; let mut n = 0; @@ -836,14 +749,12 @@ macro_rules! tuple { tuple! { T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, } impl Encodable for path::PathBuf { - #[inline] fn encode(&self, e: &mut S) -> Result<(), S::Error> { self.to_str().unwrap().encode(e) } } impl Decodable for path::PathBuf { - #[inline] fn decode(d: &mut D) -> Result { let bytes: String = Decodable::decode(d)?; Ok(path::PathBuf::from(bytes)) @@ -851,14 +762,12 @@ impl Decodable for path::PathBuf { } impl Encodable for Cell { - #[inline] fn encode(&self, s: &mut S) -> Result<(), S::Error> { self.get().encode(s) } } impl Decodable for Cell { - #[inline] fn decode(d: &mut D) -> Result, D::Error> { Ok(Cell::new(Decodable::decode(d)?)) } @@ -870,28 +779,24 @@ impl Decodable for Cell { // from `encode` when `try_borrow` returns `None`. impl Encodable for RefCell { - #[inline] fn encode(&self, s: &mut S) -> Result<(), S::Error> { self.borrow().encode(s) } } impl Decodable for RefCell { - #[inline] fn decode(d: &mut D) -> Result, D::Error> { Ok(RefCell::new(Decodable::decode(d)?)) } } impl Encodable for Arc { - #[inline] fn encode(&self, s: &mut S) -> Result<(), S::Error> { (**self).encode(s) } } impl Decodable for Arc { - #[inline] fn decode(d: &mut D) -> Result, D::Error> { Ok(Arc::new(Decodable::decode(d)?)) } @@ -913,7 +818,6 @@ pub trait SpecializationError { } impl SpecializationError for E { - #[inline] default fn not_found(trait_name: &'static str, method_name: &'static str) -> E { panic!("missing specialization: `<{} as {}<{}>>::{}` not overridden", unsafe { intrinsics::type_name::() }, @@ -932,7 +836,6 @@ pub trait SpecializedEncoder: Encoder { } impl SpecializedEncoder for E { - #[inline] default fn specialized_encode(&mut self, value: &T) -> Result<(), E::Error> { value.default_encode(self) } @@ -947,7 +850,6 @@ pub trait SpecializedDecoder: Decoder { } impl SpecializedDecoder for D { - #[inline] default fn specialized_decode(&mut self) -> Result { T::default_decode(self) } @@ -957,14 +859,12 @@ impl SpecializedDecoder for D { /// implementation which goes through `SpecializedEncoder`. pub trait UseSpecializedEncodable { /// Defaults to returning an error (see `SpecializationError`). - #[inline] fn default_encode(&self, _: &mut E) -> Result<(), E::Error> { Err(E::Error::not_found::("SpecializedEncoder", "specialized_encode")) } } impl Encodable for T { - #[inline] default fn encode(&self, e: &mut E) -> Result<(), E::Error> { E::specialized_encode(e, self) } @@ -974,14 +874,12 @@ impl Encodable for T { /// implementation which goes through `SpecializedDecoder`. pub trait UseSpecializedDecodable: Sized { /// Defaults to returning an error (see `SpecializationError`). - #[inline] fn default_decode(_: &mut D) -> Result { Err(D::Error::not_found::("SpecializedDecoder", "specialized_decode")) } } impl Decodable for T { - #[inline] default fn decode(d: &mut D) -> Result { D::specialized_decode(d) }