diff options
Diffstat (limited to 'src/libcore/to_bytes.rs')
| -rw-r--r-- | src/libcore/to_bytes.rs | 348 |
1 files changed, 2 insertions, 346 deletions
diff --git a/src/libcore/to_bytes.rs b/src/libcore/to_bytes.rs index ad42881ffa0..5b66e94c1b4 100644 --- a/src/libcore/to_bytes.rs +++ b/src/libcore/to_bytes.rs @@ -22,11 +22,6 @@ use str; pub type Cb<'self> = &'self fn(buf: &[u8]) -> bool; -#[cfg(stage0)] -pub trait IterBytes { - fn iter_bytes(&self, lsb0: bool, f: Cb); -} - /** * A trait to implement in order to make a type hashable; * This works in combination with the trait `Hash::Hash`, and @@ -34,7 +29,6 @@ pub trait IterBytes { * modified when default methods and trait inheritence are * completed. */ -#[cfg(not(stage0))] pub trait IterBytes { /** * Call the provided callback `f` one or more times with @@ -53,16 +47,6 @@ pub trait IterBytes { fn iter_bytes(&self, lsb0: bool, f: Cb) -> bool; } -#[cfg(stage0)] -impl IterBytes for bool { - #[inline(always)] - fn iter_bytes(&self, _lsb0: bool, f: Cb) { - f([ - *self as u8 - ]); - } -} -#[cfg(not(stage0))] impl IterBytes for bool { #[inline(always)] fn iter_bytes(&self, _lsb0: bool, f: Cb) -> bool { @@ -72,16 +56,6 @@ impl IterBytes for bool { } } -#[cfg(stage0)] -impl IterBytes for u8 { - #[inline(always)] - fn iter_bytes(&self, _lsb0: bool, f: Cb) { - f([ - *self - ]); - } -} -#[cfg(not(stage0))] impl IterBytes for u8 { #[inline(always)] fn iter_bytes(&self, _lsb0: bool, f: Cb) -> bool { @@ -91,24 +65,6 @@ impl IterBytes for u8 { } } -#[cfg(stage0)] -impl IterBytes for u16 { - #[inline(always)] - fn iter_bytes(&self, lsb0: bool, f: Cb) { - if lsb0 { - f([ - *self as u8, - (*self >> 8) as u8 - ]); - } else { - f([ - (*self >> 8) as u8, - *self as u8 - ]); - } - } -} -#[cfg(not(stage0))] impl IterBytes for u16 { #[inline(always)] fn iter_bytes(&self, lsb0: bool, f: Cb) -> bool { @@ -126,28 +82,6 @@ impl IterBytes for u16 { } } -#[cfg(stage0)] -impl IterBytes for u32 { - #[inline(always)] - fn iter_bytes(&self, lsb0: bool, f: Cb) { - if lsb0 { - f([ - *self as u8, - (*self >> 8) as u8, - (*self >> 16) as u8, - (*self >> 24) as u8, - ]); - } else { - f([ - (*self >> 24) as u8, - (*self >> 16) as u8, - (*self >> 8) as u8, - *self as u8 - ]); - } - } -} -#[cfg(not(stage0))] impl IterBytes for u32 { #[inline(always)] fn iter_bytes(&self, lsb0: bool, f: Cb) -> bool { @@ -169,36 +103,6 @@ impl IterBytes for u32 { } } -#[cfg(stage0)] -impl IterBytes for u64 { - #[inline(always)] - fn iter_bytes(&self, lsb0: bool, f: Cb) { - if lsb0 { - f([ - *self as u8, - (*self >> 8) as u8, - (*self >> 16) as u8, - (*self >> 24) as u8, - (*self >> 32) as u8, - (*self >> 40) as u8, - (*self >> 48) as u8, - (*self >> 56) as u8 - ]); - } else { - f([ - (*self >> 56) as u8, - (*self >> 48) as u8, - (*self >> 40) as u8, - (*self >> 32) as u8, - (*self >> 24) as u8, - (*self >> 16) as u8, - (*self >> 8) as u8, - *self as u8 - ]); - } - } -} -#[cfg(not(stage0))] impl IterBytes for u64 { #[inline(always)] fn iter_bytes(&self, lsb0: bool, f: Cb) -> bool { @@ -228,14 +132,6 @@ impl IterBytes for u64 { } } -#[cfg(stage0)] -impl IterBytes for i8 { - #[inline(always)] - fn iter_bytes(&self, lsb0: bool, f: Cb) { - (*self as u8).iter_bytes(lsb0, f) - } -} -#[cfg(not(stage0))] impl IterBytes for i8 { #[inline(always)] fn iter_bytes(&self, lsb0: bool, f: Cb) -> bool { @@ -243,14 +139,6 @@ impl IterBytes for i8 { } } -#[cfg(stage0)] -impl IterBytes for i16 { - #[inline(always)] - fn iter_bytes(&self, lsb0: bool, f: Cb) { - (*self as u16).iter_bytes(lsb0, f) - } -} -#[cfg(not(stage0))] impl IterBytes for i16 { #[inline(always)] fn iter_bytes(&self, lsb0: bool, f: Cb) -> bool { @@ -258,14 +146,6 @@ impl IterBytes for i16 { } } -#[cfg(stage0)] -impl IterBytes for i32 { - #[inline(always)] - fn iter_bytes(&self, lsb0: bool, f: Cb) { - (*self as u32).iter_bytes(lsb0, f) - } -} -#[cfg(not(stage0))] impl IterBytes for i32 { #[inline(always)] fn iter_bytes(&self, lsb0: bool, f: Cb) -> bool { @@ -273,14 +153,6 @@ impl IterBytes for i32 { } } -#[cfg(stage0)] -impl IterBytes for i64 { - #[inline(always)] - fn iter_bytes(&self, lsb0: bool, f: Cb) { - (*self as u64).iter_bytes(lsb0, f) - } -} -#[cfg(not(stage0))] impl IterBytes for i64 { #[inline(always)] fn iter_bytes(&self, lsb0: bool, f: Cb) -> bool { @@ -288,14 +160,6 @@ impl IterBytes for i64 { } } -#[cfg(stage0)] -impl IterBytes for char { - #[inline(always)] - fn iter_bytes(&self, lsb0: bool, f: Cb) { - (*self as u32).iter_bytes(lsb0, f) - } -} -#[cfg(not(stage0))] impl IterBytes for char { #[inline(always)] fn iter_bytes(&self, lsb0: bool, f: Cb) -> bool { @@ -303,14 +167,7 @@ impl IterBytes for char { } } -#[cfg(target_word_size = "32", stage0)] -impl IterBytes for uint { - #[inline(always)] - fn iter_bytes(&self, lsb0: bool, f: Cb) { - (*self as u32).iter_bytes(lsb0, f) - } -} -#[cfg(target_word_size = "32", not(stage0))] +#[cfg(target_word_size = "32")] impl IterBytes for uint { #[inline(always)] fn iter_bytes(&self, lsb0: bool, f: Cb) -> bool { @@ -318,14 +175,7 @@ impl IterBytes for uint { } } -#[cfg(target_word_size = "64", stage0)] -impl IterBytes for uint { - #[inline(always)] - fn iter_bytes(&self, lsb0: bool, f: Cb) { - (*self as u64).iter_bytes(lsb0, f) - } -} -#[cfg(target_word_size = "64", not(stage0))] +#[cfg(target_word_size = "64")] impl IterBytes for uint { #[inline(always)] fn iter_bytes(&self, lsb0: bool, f: Cb) -> bool { @@ -333,14 +183,6 @@ impl IterBytes for uint { } } -#[cfg(stage0)] -impl IterBytes for int { - #[inline(always)] - fn iter_bytes(&self, lsb0: bool, f: Cb) { - (*self as uint).iter_bytes(lsb0, f) - } -} -#[cfg(not(stage0))] impl IterBytes for int { #[inline(always)] fn iter_bytes(&self, lsb0: bool, f: Cb) -> bool { @@ -348,18 +190,6 @@ impl IterBytes for int { } } -#[cfg(stage0)] -impl<'self,A:IterBytes> IterBytes for &'self [A] { - #[inline(always)] - fn iter_bytes(&self, lsb0: bool, f: Cb) { - for (*self).each |elt| { - do elt.iter_bytes(lsb0) |bytes| { - f(bytes) - } - } - } -} -#[cfg(not(stage0))] impl<'self,A:IterBytes> IterBytes for &'self [A] { #[inline(always)] fn iter_bytes(&self, lsb0: bool, f: Cb) -> bool { @@ -367,18 +197,6 @@ impl<'self,A:IterBytes> IterBytes for &'self [A] { } } -#[cfg(stage0)] -impl<A:IterBytes,B:IterBytes> IterBytes for (A,B) { - #[inline(always)] - fn iter_bytes(&self, lsb0: bool, f: Cb) { - match *self { - (ref a, ref b) => { - iter_bytes_2(a, b, lsb0, f); - } - } - } -} -#[cfg(not(stage0))] impl<A:IterBytes,B:IterBytes> IterBytes for (A,B) { #[inline(always)] fn iter_bytes(&self, lsb0: bool, f: Cb) -> bool { @@ -388,18 +206,6 @@ impl<A:IterBytes,B:IterBytes> IterBytes for (A,B) { } } -#[cfg(stage0)] -impl<A:IterBytes,B:IterBytes,C:IterBytes> IterBytes for (A,B,C) { - #[inline(always)] - fn iter_bytes(&self, lsb0: bool, f: Cb) { - match *self { - (ref a, ref b, ref c) => { - iter_bytes_3(a, b, c, lsb0, f); - } - } - } -} -#[cfg(not(stage0))] impl<A:IterBytes,B:IterBytes,C:IterBytes> IterBytes for (A,B,C) { #[inline(always)] fn iter_bytes(&self, lsb0: bool, f: Cb) -> bool { @@ -416,14 +222,6 @@ fn borrow<'x,A>(a: &'x [A]) -> &'x [A] { a } -#[cfg(stage0)] -impl<A:IterBytes> IterBytes for ~[A] { - #[inline(always)] - fn iter_bytes(&self, lsb0: bool, f: Cb) { - borrow(*self).iter_bytes(lsb0, f) - } -} -#[cfg(not(stage0))] impl<A:IterBytes> IterBytes for ~[A] { #[inline(always)] fn iter_bytes(&self, lsb0: bool, f: Cb) -> bool { @@ -431,14 +229,6 @@ impl<A:IterBytes> IterBytes for ~[A] { } } -#[cfg(stage0)] -impl<A:IterBytes> IterBytes for @[A] { - #[inline(always)] - fn iter_bytes(&self, lsb0: bool, f: Cb) { - borrow(*self).iter_bytes(lsb0, f) - } -} -#[cfg(not(stage0))] impl<A:IterBytes> IterBytes for @[A] { #[inline(always)] fn iter_bytes(&self, lsb0: bool, f: Cb) -> bool { @@ -449,57 +239,18 @@ impl<A:IterBytes> IterBytes for @[A] { // NOTE: remove all of these after a snapshot, the new for-loop iteration // protocol makes these unnecessary. -#[cfg(stage0)] -pub fn iter_bytes_2<A:IterBytes,B:IterBytes>(a: &A, b: &B, - lsb0: bool, z: Cb) { - let mut flag = true; - a.iter_bytes(lsb0, |bytes| {flag = z(bytes); flag}); - if !flag { return; } - b.iter_bytes(lsb0, |bytes| {flag = z(bytes); flag}); -} -#[cfg(not(stage0))] #[inline(always)] pub fn iter_bytes_2<A:IterBytes,B:IterBytes>(a: &A, b: &B, lsb0: bool, z: Cb) -> bool { a.iter_bytes(lsb0, z) && b.iter_bytes(lsb0, z) } -#[cfg(stage0)] -pub fn iter_bytes_3<A: IterBytes, - B: IterBytes, - C: IterBytes>(a: &A, b: &B, c: &C, - lsb0: bool, z: Cb) { - let mut flag = true; - a.iter_bytes(lsb0, |bytes| {flag = z(bytes); flag}); - if !flag { return; } - b.iter_bytes(lsb0, |bytes| {flag = z(bytes); flag}); - if !flag { return; } - c.iter_bytes(lsb0, |bytes| {flag = z(bytes); flag}); -} -#[cfg(not(stage0))] pub fn iter_bytes_3<A: IterBytes, B: IterBytes, C: IterBytes>(a: &A, b: &B, c: &C, lsb0: bool, z: Cb) -> bool { a.iter_bytes(lsb0, z) && b.iter_bytes(lsb0, z) && c.iter_bytes(lsb0, z) } -#[cfg(stage0)] -pub fn iter_bytes_4<A: IterBytes, - B: IterBytes, - C: IterBytes, - D: IterBytes>(a: &A, b: &B, c: &C, - d: &D, - lsb0: bool, z: Cb) { - let mut flag = true; - a.iter_bytes(lsb0, |bytes| {flag = z(bytes); flag}); - if !flag { return; } - b.iter_bytes(lsb0, |bytes| {flag = z(bytes); flag}); - if !flag { return; } - c.iter_bytes(lsb0, |bytes| {flag = z(bytes); flag}); - if !flag { return; } - d.iter_bytes(lsb0, |bytes| {flag = z(bytes); flag}); -} -#[cfg(not(stage0))] pub fn iter_bytes_4<A: IterBytes, B: IterBytes, C: IterBytes, @@ -510,26 +261,6 @@ pub fn iter_bytes_4<A: IterBytes, d.iter_bytes(lsb0, z) } -#[cfg(stage0)] -pub fn iter_bytes_5<A: IterBytes, - B: IterBytes, - C: IterBytes, - D: IterBytes, - E: IterBytes>(a: &A, b: &B, c: &C, - d: &D, e: &E, - lsb0: bool, z: Cb) { - let mut flag = true; - a.iter_bytes(lsb0, |bytes| {flag = z(bytes); flag}); - if !flag { return; } - b.iter_bytes(lsb0, |bytes| {flag = z(bytes); flag}); - if !flag { return; } - c.iter_bytes(lsb0, |bytes| {flag = z(bytes); flag}); - if !flag { return; } - d.iter_bytes(lsb0, |bytes| {flag = z(bytes); flag}); - if !flag { return; } - e.iter_bytes(lsb0, |bytes| {flag = z(bytes); flag}); -} -#[cfg(not(stage0))] pub fn iter_bytes_5<A: IterBytes, B: IterBytes, C: IterBytes, @@ -541,16 +272,6 @@ pub fn iter_bytes_5<A: IterBytes, d.iter_bytes(lsb0, z) && e.iter_bytes(lsb0, z) } -#[cfg(stage0)] -impl<'self> IterBytes for &'self str { - #[inline(always)] - fn iter_bytes(&self, _lsb0: bool, f: Cb) { - do str::byte_slice(*self) |bytes| { - f(bytes); - } - } -} -#[cfg(not(stage0))] impl<'self> IterBytes for &'self str { #[inline(always)] fn iter_bytes(&self, _lsb0: bool, f: Cb) -> bool { @@ -560,16 +281,6 @@ impl<'self> IterBytes for &'self str { } } -#[cfg(stage0)] -impl IterBytes for ~str { - #[inline(always)] - fn iter_bytes(&self, _lsb0: bool, f: Cb) { - do str::byte_slice(*self) |bytes| { - f(bytes); - } - } -} -#[cfg(not(stage0))] impl IterBytes for ~str { #[inline(always)] fn iter_bytes(&self, _lsb0: bool, f: Cb) -> bool { @@ -579,16 +290,6 @@ impl IterBytes for ~str { } } -#[cfg(stage0)] -impl IterBytes for @str { - #[inline(always)] - fn iter_bytes(&self, _lsb0: bool, f: Cb) { - do str::byte_slice(*self) |bytes| { - f(bytes); - } - } -} -#[cfg(not(stage0))] impl IterBytes for @str { #[inline(always)] fn iter_bytes(&self, _lsb0: bool, f: Cb) -> bool { @@ -598,17 +299,6 @@ impl IterBytes for @str { } } -#[cfg(stage0)] -impl<A:IterBytes> IterBytes for Option<A> { - #[inline(always)] - fn iter_bytes(&self, lsb0: bool, f: Cb) { - match *self { - Some(ref a) => iter_bytes_2(&0u8, a, lsb0, f), - None => 1u8.iter_bytes(lsb0, f) - } - } -} -#[cfg(not(stage0))] impl<A:IterBytes> IterBytes for Option<A> { #[inline(always)] fn iter_bytes(&self, lsb0: bool, f: Cb) -> bool { @@ -619,14 +309,6 @@ impl<A:IterBytes> IterBytes for Option<A> { } } -#[cfg(stage0)] -impl<'self,A:IterBytes> IterBytes for &'self A { - #[inline(always)] - fn iter_bytes(&self, lsb0: bool, f: Cb) { - (**self).iter_bytes(lsb0, f); - } -} -#[cfg(not(stage0))] impl<'self,A:IterBytes> IterBytes for &'self A { #[inline(always)] fn iter_bytes(&self, lsb0: bool, f: Cb) -> bool { @@ -634,14 +316,6 @@ impl<'self,A:IterBytes> IterBytes for &'self A { } } -#[cfg(stage0)] -impl<A:IterBytes> IterBytes for @A { - #[inline(always)] - fn iter_bytes(&self, lsb0: bool, f: Cb) { - (**self).iter_bytes(lsb0, f); - } -} -#[cfg(not(stage0))] impl<A:IterBytes> IterBytes for @A { #[inline(always)] fn iter_bytes(&self, lsb0: bool, f: Cb) -> bool { @@ -649,14 +323,6 @@ impl<A:IterBytes> IterBytes for @A { } } -#[cfg(stage0)] -impl<A:IterBytes> IterBytes for ~A { - #[inline(always)] - fn iter_bytes(&self, lsb0: bool, f: Cb) { - (**self).iter_bytes(lsb0, f); - } -} -#[cfg(not(stage0))] impl<A:IterBytes> IterBytes for ~A { #[inline(always)] fn iter_bytes(&self, lsb0: bool, f: Cb) -> bool { @@ -666,16 +332,6 @@ impl<A:IterBytes> IterBytes for ~A { // NB: raw-pointer IterBytes does _not_ dereference // to the target; it just gives you the pointer-bytes. -#[cfg(stage0)] -impl<A> IterBytes for *const A { - #[inline(always)] - fn iter_bytes(&self, lsb0: bool, f: Cb) { - (*self as uint).iter_bytes(lsb0, f); - } -} -// NB: raw-pointer IterBytes does _not_ dereference -// to the target; it just gives you the pointer-bytes. -#[cfg(not(stage0))] impl<A> IterBytes for *const A { #[inline(always)] fn iter_bytes(&self, lsb0: bool, f: Cb) -> bool { |
