Navigation Menu

Skip to content

Commit

Permalink
Use slice operators
Browse files Browse the repository at this point in the history
  • Loading branch information
sfackler committed Oct 5, 2014
1 parent 4bf6f82 commit a1b5030
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 22 deletions.
20 changes: 10 additions & 10 deletions phf/tests/test.rs
Expand Up @@ -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]
Expand Down Expand Up @@ -248,7 +248,7 @@ mod set {
"hello",
"world",
};
assert!(SET.contains_equiv(&"hello".to_string().as_slice()));
assert!(SET.contains_equiv(&"hello".to_string()[]));
}
}

Expand Down Expand Up @@ -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]
Expand Down Expand Up @@ -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()[]));
}
}

Expand Down Expand Up @@ -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]
Expand All @@ -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()[]));
}
}
18 changes: 9 additions & 9 deletions phf_mac/src/lib.rs
Expand Up @@ -45,11 +45,11 @@ fn expand_phf_map(cx: &mut ExtCtxt, sp: Span, tts: &[TokenTree]) -> Box<MacResul
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_map(cx, sp, entries, state)
}
Expand All @@ -60,11 +60,11 @@ fn expand_phf_set(cx: &mut ExtCtxt, sp: Span, tts: &[TokenTree]) -> Box<MacResul
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_set(cx, sp, entries, state)
}
Expand All @@ -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)
}
Expand All @@ -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)
}
Expand Down Expand Up @@ -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");
}
Expand Down
6 changes: 3 additions & 3 deletions phf_mac/src/util.rs
Expand Up @@ -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),
Expand Down Expand Up @@ -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;
Expand All @@ -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
Expand Down

0 comments on commit a1b5030

Please sign in to comment.