From 09f7713dd45c3a0b37073115575697c256238b18 Mon Sep 17 00:00:00 2001 From: Jorge Aparicio Date: Thu, 27 Nov 2014 14:28:51 -0500 Subject: [PATCH] libserialize: remove unnecessary `as_slice()` calls --- src/libserialize/base64.rs | 36 ++++++++++++++++-------------------- src/libserialize/hex.rs | 26 +++++++++++--------------- src/libserialize/json.rs | 6 +++--- 3 files changed, 30 insertions(+), 38 deletions(-) diff --git a/src/libserialize/base64.rs b/src/libserialize/base64.rs index b7d8885a5f9..8efb8e5b78d 100644 --- a/src/libserialize/base64.rs +++ b/src/libserialize/base64.rs @@ -298,7 +298,6 @@ mod tests { #[test] fn test_to_base64_line_break() { assert!(![0u8, ..1000].to_base64(Config {line_length: None, ..STANDARD}) - .as_slice() .contains("\r\n")); assert_eq!("foobar".as_bytes().to_base64(Config {line_length: Some(4), ..STANDARD}), @@ -319,26 +318,26 @@ mod tests { #[test] fn test_from_base64_basic() { - assert_eq!("".from_base64().unwrap().as_slice(), "".as_bytes()); - assert_eq!("Zg==".from_base64().unwrap().as_slice(), "f".as_bytes()); - assert_eq!("Zm8=".from_base64().unwrap().as_slice(), "fo".as_bytes()); - assert_eq!("Zm9v".from_base64().unwrap().as_slice(), "foo".as_bytes()); - assert_eq!("Zm9vYg==".from_base64().unwrap().as_slice(), "foob".as_bytes()); - assert_eq!("Zm9vYmE=".from_base64().unwrap().as_slice(), "fooba".as_bytes()); - assert_eq!("Zm9vYmFy".from_base64().unwrap().as_slice(), "foobar".as_bytes()); + assert_eq!("".from_base64().unwrap(), b""); + assert_eq!("Zg==".from_base64().unwrap(), b"f"); + assert_eq!("Zm8=".from_base64().unwrap(), b"fo"); + assert_eq!("Zm9v".from_base64().unwrap(), b"foo"); + assert_eq!("Zm9vYg==".from_base64().unwrap(), b"foob"); + assert_eq!("Zm9vYmE=".from_base64().unwrap(), b"fooba"); + assert_eq!("Zm9vYmFy".from_base64().unwrap(), b"foobar"); } #[test] fn test_from_base64_bytes() { - assert_eq!(b"Zm9vYmFy".from_base64().unwrap().as_slice(), "foobar".as_bytes()); + assert_eq!(b"Zm9vYmFy".from_base64().unwrap(), b"foobar"); } #[test] fn test_from_base64_newlines() { - assert_eq!("Zm9v\r\nYmFy".from_base64().unwrap().as_slice(), - "foobar".as_bytes()); - assert_eq!("Zm9vYg==\r\n".from_base64().unwrap().as_slice(), - "foob".as_bytes()); + assert_eq!("Zm9v\r\nYmFy".from_base64().unwrap(), + b"foobar"); + assert_eq!("Zm9vYg==\r\n".from_base64().unwrap(), + b"foob"); } #[test] @@ -364,13 +363,10 @@ mod tests { for _ in range(0u, 1000) { let times = task_rng().gen_range(1u, 100); let v = Vec::from_fn(times, |_| random::()); - assert_eq!(v.as_slice() - .to_base64(STANDARD) - .as_slice() + assert_eq!(v.to_base64(STANDARD) .from_base64() - .unwrap() - .as_slice(), - v.as_slice()); + .unwrap(), + v); } } @@ -390,7 +386,7 @@ mod tests { ウヰノオクヤマ ケフコエテ アサキユメミシ ヱヒモセスン"; let sb = s.as_bytes().to_base64(STANDARD); b.iter(|| { - sb.as_slice().from_base64().unwrap(); + sb.from_base64().unwrap(); }); b.bytes = sb.len() as u64; } diff --git a/src/libserialize/hex.rs b/src/libserialize/hex.rs index 2a3c410ba7c..443a31f7493 100644 --- a/src/libserialize/hex.rs +++ b/src/libserialize/hex.rs @@ -163,10 +163,10 @@ mod tests { #[test] pub fn test_from_hex_okay() { - assert_eq!("666f6f626172".from_hex().unwrap().as_slice(), - "foobar".as_bytes()); - assert_eq!("666F6F626172".from_hex().unwrap().as_slice(), - "foobar".as_bytes()); + assert_eq!("666f6f626172".from_hex().unwrap(), + b"foobar"); + assert_eq!("666F6F626172".from_hex().unwrap(), + b"foobar"); } #[test] @@ -182,8 +182,8 @@ mod tests { #[test] pub fn test_from_hex_ignores_whitespace() { - assert_eq!("666f 6f6\r\n26172 ".from_hex().unwrap().as_slice(), - "foobar".as_bytes()); + assert_eq!("666f 6f6\r\n26172 ".from_hex().unwrap(), + b"foobar"); } #[test] @@ -197,15 +197,11 @@ mod tests { pub fn test_from_hex_all_bytes() { for i in range(0u, 256) { let ii: &[u8] = &[i as u8]; - assert_eq!(format!("{:02x}", i as uint).as_slice() - .from_hex() - .unwrap() - .as_slice(), + assert_eq!(format!("{:02x}", i as uint).from_hex() + .unwrap(), ii); - assert_eq!(format!("{:02X}", i as uint).as_slice() - .from_hex() - .unwrap() - .as_slice(), + assert_eq!(format!("{:02X}", i as uint).from_hex() + .unwrap(), ii); } } @@ -226,7 +222,7 @@ mod tests { ウヰノオクヤマ ケフコエテ アサキユメミシ ヱヒモセスン"; let sb = s.as_bytes().to_hex(); b.iter(|| { - sb.as_slice().from_hex().unwrap(); + sb.from_hex().unwrap(); }); b.bytes = sb.len() as u64; } diff --git a/src/libserialize/json.rs b/src/libserialize/json.rs index fa82eb93fae..abf2341a76c 100644 --- a/src/libserialize/json.rs +++ b/src/libserialize/json.rs @@ -2039,7 +2039,7 @@ impl ::Decoder for Decoder { fn read_char(&mut self) -> DecodeResult { let s = try!(self.read_str()); { - let mut it = s.as_slice().chars(); + let mut it = s.chars(); match (it.next(), it.next()) { // exactly one character (Some(c), None) => return Ok(c), @@ -2860,7 +2860,7 @@ mod tests { for &(i, o) in s.iter() { let v: string::String = super::decode(i).unwrap(); - assert_eq!(v.as_slice(), o); + assert_eq!(v, o); } } @@ -3778,7 +3778,7 @@ mod tests { fn bench_streaming_large(b: &mut Bencher) { let src = big_json(); b.iter( || { - let mut parser = Parser::new(src.as_slice().chars()); + let mut parser = Parser::new(src.chars()); loop { match parser.next() { None => return,