From a1b503023f516753fcd95061b1b303d21bb44a91 Mon Sep 17 00:00:00 2001 From: Steven Fackler Date: Sun, 5 Oct 2014 12:11:31 -0700 Subject: [PATCH] Use slice operators --- phf/tests/test.rs | 20 ++++++++++---------- phf_mac/src/lib.rs | 18 +++++++++--------- phf_mac/src/util.rs | 6 +++--- 3 files changed, 22 insertions(+), 22 deletions(-) diff --git a/phf/tests/test.rs b/phf/tests/test.rs index f214e93a..80805a5d 100644 --- a/phf/tests/test.rs +++ b/phf/tests/test.rs @@ -112,7 +112,7 @@ mod map { static MAP: PhfMap<&'static str, int> = phf_map!( "a" => 0, ); - assert_eq!(Some(&0), MAP.find_equiv(&"a".to_string().as_slice())); + assert_eq!(Some(&0), MAP.find_equiv(&"a".to_string()[])); } #[test] @@ -248,7 +248,7 @@ mod set { "hello", "world", }; - assert!(SET.contains_equiv(&"hello".to_string().as_slice())); + assert!(SET.contains_equiv(&"hello".to_string()[])); } } @@ -289,9 +289,9 @@ mod ordered_map { assert_eq!(None, MAP.find_index(&"xyz")); assert_eq!(&"baz", MAP.keys().idx(MAP.find_index(&"baz").unwrap()).unwrap()); - assert_eq!(Some(0), MAP.find_index_equiv(&"foo".to_string().as_slice())); - assert_eq!(Some(2), MAP.find_index_equiv(&"baz".to_string().as_slice())); - assert_eq!(None, MAP.find_index_equiv(&"xyz".to_string().as_slice())); + assert_eq!(Some(0), MAP.find_index_equiv(&"foo".to_string()[])); + assert_eq!(Some(2), MAP.find_index_equiv(&"baz".to_string()[])); + assert_eq!(None, MAP.find_index_equiv(&"xyz".to_string()[])); } #[test] @@ -349,7 +349,7 @@ mod ordered_map { static MAP: PhfOrderedMap<&'static str, int> = phf_ordered_map!( "a" => 0, ); - assert_eq!(Some(&0), MAP.find_equiv(&"a".to_string().as_slice())); + assert_eq!(Some(&0), MAP.find_equiv(&"a".to_string()[])); } } @@ -392,9 +392,9 @@ mod ordered_set { assert_eq!(None, SET.find_index(&"xyz")); assert_eq!(&"baz", SET.iter().idx(SET.find_index(&"baz").unwrap()).unwrap()); - assert_eq!(Some(0), SET.find_index_equiv(&"foo".to_string().as_slice())); - assert_eq!(Some(2), SET.find_index_equiv(&"baz".to_string().as_slice())); - assert_eq!(None, SET.find_index_equiv(&"xyz".to_string().as_slice())); + assert_eq!(Some(0), SET.find_index_equiv(&"foo".to_string()[])); + assert_eq!(Some(2), SET.find_index_equiv(&"baz".to_string()[])); + assert_eq!(None, SET.find_index_equiv(&"xyz".to_string()[])); } #[test] @@ -414,6 +414,6 @@ mod ordered_set { "hello", "world", }; - assert!(SET.contains_equiv(&"hello".to_string().as_slice())); + assert!(SET.contains_equiv(&"hello".to_string()[])); } } diff --git a/phf_mac/src/lib.rs b/phf_mac/src/lib.rs index 2ae115df..557667e6 100644 --- a/phf_mac/src/lib.rs +++ b/phf_mac/src/lib.rs @@ -45,11 +45,11 @@ fn expand_phf_map(cx: &mut ExtCtxt, sp: Span, tts: &[TokenTree]) -> Box return DummyResult::expr(sp) }; - if has_duplicates(cx, sp, entries.as_slice()) { + if has_duplicates(cx, sp, entries[]) { return DummyResult::expr(sp); } - let state = generate_hash(cx, sp, entries.as_slice()); + let state = generate_hash(cx, sp, entries[]); create_map(cx, sp, entries, state) } @@ -60,11 +60,11 @@ fn expand_phf_set(cx: &mut ExtCtxt, sp: Span, tts: &[TokenTree]) -> Box return DummyResult::expr(sp) }; - if has_duplicates(cx, sp, entries.as_slice()) { + if has_duplicates(cx, sp, entries[]) { return DummyResult::expr(sp); } - let state = generate_hash(cx, sp, entries.as_slice()); + let state = generate_hash(cx, sp, entries[]); create_set(cx, sp, entries, state) } @@ -75,11 +75,11 @@ fn expand_phf_ordered_map(cx: &mut ExtCtxt, sp: Span, tts: &[TokenTree]) -> Box< None => return DummyResult::expr(sp), }; - if has_duplicates(cx, sp, entries.as_slice()) { + if has_duplicates(cx, sp, entries[]) { return DummyResult::expr(sp); } - let state = generate_hash(cx, sp, entries.as_slice()); + let state = generate_hash(cx, sp, entries[]); create_ordered_map(cx, sp, entries, state) } @@ -90,11 +90,11 @@ fn expand_phf_ordered_set(cx: &mut ExtCtxt, sp: Span, tts: &[TokenTree]) -> Box< None => return DummyResult::expr(sp) }; - if has_duplicates(cx, sp, entries.as_slice()) { + if has_duplicates(cx, sp, entries[]) { return DummyResult::expr(sp); } - let state = generate_hash(cx, sp, entries.as_slice()); + let state = generate_hash(cx, sp, entries[]); create_ordered_set(cx, sp, entries, state) } @@ -220,7 +220,7 @@ fn has_duplicates(cx: &mut ExtCtxt, sp: Span, entries: &[Entry]) -> bool { } dups = true; - cx.span_err(sp, format!("duplicate key {}", pprust::expr_to_string(&**key)).as_slice()); + cx.span_err(sp, format!("duplicate key {}", pprust::expr_to_string(&**key))[]); for span in spans.iter() { cx.span_note(*span, "one occurrence here"); } diff --git a/phf_mac/src/util.rs b/phf_mac/src/util.rs index f15c052e..1bf2b027 100644 --- a/phf_mac/src/util.rs +++ b/phf_mac/src/util.rs @@ -60,7 +60,7 @@ impl PhfHash for Key { fn phf_hash(&self, key: u64) -> (u32, u32, u32) { match *self { KeyStr(ref s) => s.get().phf_hash(key), - KeyBinary(ref b) => b.as_slice().phf_hash(key), + KeyBinary(ref b) => (**b)[].phf_hash(key), KeyChar(c) => c.phf_hash(key), KeyU8(b) => b.phf_hash(key), KeyI8(b) => b.phf_hash(key), @@ -92,7 +92,7 @@ pub fn generate_hash(cx: &mut ExtCtxt, sp: Span, entries: &[Entry]) -> HashState let start = time::precise_time_s(); let state; loop { - match try_generate_hash(entries.as_slice(), &mut rng) { + match try_generate_hash(entries[], &mut rng) { Some(s) => { state = s; break; @@ -102,7 +102,7 @@ pub fn generate_hash(cx: &mut ExtCtxt, sp: Span, entries: &[Entry]) -> HashState } let time = time::precise_time_s() - start; if os::getenv("PHF_STATS").is_some() { - cx.span_note(sp, format!("PHF generation took {} seconds", time).as_slice()); + cx.span_note(sp, format!("PHF generation took {} seconds", time)[]); } state