Skip to content

Commit

Permalink
Auto merge of rust-lang#21680 - japaric:slice, r=alexcrichton
Browse files Browse the repository at this point in the history
Replaces `slice_*` method calls with slicing syntax, and removes `as_slice()` calls that are redundant due to `Deref`.
  • Loading branch information
bors committed Jan 29, 2015
2 parents c5961ad + bce81e2 commit bedd810
Show file tree
Hide file tree
Showing 59 changed files with 156 additions and 160 deletions.
8 changes: 4 additions & 4 deletions src/compiletest/compiletest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -369,8 +369,8 @@ pub fn make_metrics_test_closure(config: &Config, testfile: &Path) -> test::Test
fn extract_gdb_version(full_version_line: Option<String>) -> Option<String> {
match full_version_line {
Some(ref full_version_line)
if full_version_line.as_slice().trim().len() > 0 => {
let full_version_line = full_version_line.as_slice().trim();
if full_version_line.trim().len() > 0 => {
let full_version_line = full_version_line.trim();

// used to be a regex "(^|[^0-9])([0-9]\.[0-9])([^0-9]|$)"
for (pos, c) in full_version_line.char_indices() {
Expand Down Expand Up @@ -409,8 +409,8 @@ fn extract_lldb_version(full_version_line: Option<String>) -> Option<String> {

match full_version_line {
Some(ref full_version_line)
if full_version_line.as_slice().trim().len() > 0 => {
let full_version_line = full_version_line.as_slice().trim();
if full_version_line.trim().len() > 0 => {
let full_version_line = full_version_line.trim();

for (pos, l) in full_version_line.char_indices() {
if l != 'l' && l != 'L' { continue }
Expand Down
8 changes: 4 additions & 4 deletions src/compiletest/header.rs
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ pub fn is_test_ignored(config: &Config, testfile: &Path) -> bool {
}
fn ignore_stage(config: &Config) -> String {
format!("ignore-{}",
config.stage_id.as_slice().split('-').next().unwrap())
config.stage_id.split('-').next().unwrap())
}
fn ignore_gdb(config: &Config, line: &str) -> bool {
if config.mode != common::DebugInfoGdb {
Expand Down Expand Up @@ -231,11 +231,11 @@ fn iter_header<F>(testfile: &Path, mut it: F) -> bool where
// module or function. This doesn't seem to be an optimization
// with a warm page cache. Maybe with a cold one.
let ln = ln.unwrap();
if ln.as_slice().starts_with("fn") ||
ln.as_slice().starts_with("mod") {
if ln.starts_with("fn") ||
ln.starts_with("mod") {
return true;
} else {
if !(it(ln.as_slice().trim())) {
if !(it(ln.trim())) {
return false;
}
}
Expand Down
12 changes: 6 additions & 6 deletions src/compiletest/runtest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -777,7 +777,7 @@ fn parse_debugger_commands(file_path: &Path, debugger_prefix: &str)
for line in reader.lines() {
match line {
Ok(line) => {
if line.as_slice().contains("#break") {
if line.contains("#break") {
breakpoint_lines.push(counter);
}

Expand Down Expand Up @@ -843,7 +843,7 @@ fn check_debugger_output(debugger_run_result: &ProcRes, check_lines: &[String])
// check if each line in props.check_lines appears in the
// output (in order)
let mut i = 0u;
for line in debugger_run_result.stdout.as_slice().lines() {
for line in debugger_run_result.stdout.lines() {
let mut rest = line.trim();
let mut first = true;
let mut failed = false;
Expand Down Expand Up @@ -895,7 +895,7 @@ fn check_error_patterns(props: &TestProps,
let mut next_err_idx = 0u;
let mut next_err_pat = &props.error_patterns[next_err_idx];
let mut done = false;
for line in output_to_check.as_slice().lines() {
for line in output_to_check.lines() {
if line.contains(next_err_pat.as_slice()) {
debug!("found error pattern {}", next_err_pat);
next_err_idx += 1u;
Expand Down Expand Up @@ -924,7 +924,7 @@ fn check_error_patterns(props: &TestProps,
}

fn check_no_compiler_crash(proc_res: &ProcRes) {
for line in proc_res.stderr.as_slice().lines() {
for line in proc_res.stderr.lines() {
if line.starts_with("error: internal compiler error:") {
fatal_proc_rec("compiler encountered internal error",
proc_res);
Expand Down Expand Up @@ -983,7 +983,7 @@ fn check_expected_errors(expected_errors: Vec<errors::ExpectedError> ,
// filename:line1:col1: line2:col2: *warning:* msg
// where line1:col1: is the starting point, line2:col2:
// is the ending point, and * represents ANSI color codes.
for line in proc_res.stderr.as_slice().lines() {
for line in proc_res.stderr.lines() {
let mut was_expected = false;
for (i, ee) in expected_errors.iter().enumerate() {
if !found_flags[i] {
Expand Down Expand Up @@ -1536,7 +1536,7 @@ fn _arm_exec_compiled_test(config: &Config,
.expect(format!("failed to exec `{}`", config.adb_path).as_slice());

let mut exitcode: int = 0;
for c in exitcode_out.as_slice().chars() {
for c in exitcode_out.chars() {
if !c.is_numeric() { break; }
exitcode = exitcode * 10 + match c {
'0' ... '9' => c as int - ('0' as int),
Expand Down
21 changes: 10 additions & 11 deletions src/grammar/verify.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ fn parse_token_list(file: &str) -> HashMap<String, token::Token> {
None => continue
};

let val = line.slice_to(eq);
let num = line.slice_from(eq + 1);
let val = &line[..eq];
let num = &line[eq + 1..];

let tok = match val {
"SHR" => token::BinOp(token::Shr),
Expand Down Expand Up @@ -136,27 +136,27 @@ fn str_to_binop(s: &str) -> token::BinOpToken {
fn fix(mut lit: &str) -> ast::Name {
if lit.char_at(0) == 'r' {
if lit.char_at(1) == 'b' {
lit = lit.slice_from(2)
lit = &lit[2..]
} else {
lit = lit.slice_from(1);
lit = &lit[1..];
}
} else if lit.char_at(0) == 'b' {
lit = lit.slice_from(1);
lit = &lit[1..];
}

let leading_hashes = count(lit);

// +1/-1 to adjust for single quotes
parse::token::intern(lit.slice(leading_hashes + 1, lit.len() - leading_hashes - 1))
parse::token::intern(&lit[leading_hashes + 1..lit.len() - leading_hashes - 1])
}

/// Assuming a char/byte literal, strip the 'b' prefix and the single quotes.
fn fixchar(mut lit: &str) -> ast::Name {
if lit.char_at(0) == 'b' {
lit = lit.slice_from(1);
lit = &lit[1..];
}

parse::token::intern(lit.slice(1, lit.len() - 1))
parse::token::intern(&lit[1..lit.len() - 1])
}

fn count(lit: &str) -> usize {
Expand Down Expand Up @@ -187,8 +187,7 @@ fn parse_antlr_token(s: &str, tokens: &HashMap<String, token::Token>) -> TokenAn

let real_tok = match *proto_tok {
token::BinOp(..) => token::BinOp(str_to_binop(content)),
token::BinOpEq(..) => token::BinOpEq(str_to_binop(content.slice_to(
content.len() - 1))),
token::BinOpEq(..) => token::BinOpEq(str_to_binop(&content[..content.len() - 1])),
token::Literal(token::Str_(..), n) => token::Literal(token::Str_(fix(content)), n),
token::Literal(token::StrRaw(..), n) => token::Literal(token::StrRaw(fix(content),
count(content)), n),
Expand Down Expand Up @@ -249,7 +248,7 @@ fn main() {
let mut stdin = std::io::stdin();
let mut lock = stdin.lock();
let lines = lock.lines();
let mut antlr_tokens = lines.map(|l| parse_antlr_token(l.unwrap().as_slice().trim(),
let mut antlr_tokens = lines.map(|l| parse_antlr_token(l.unwrap().trim(),
&token_map));

let code = File::open(&Path::new(args[1].as_slice())).unwrap().read_to_string().unwrap();
Expand Down
62 changes: 31 additions & 31 deletions src/libcollections/slice.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1594,21 +1594,21 @@ mod tests {
#[test]
fn test_get() {
let mut a = vec![11i];
assert_eq!(a.as_slice().get(1), None);
assert_eq!(a.get(1), None);
a = vec![11i, 12];
assert_eq!(a.as_slice().get(1).unwrap(), &12);
assert_eq!(a.get(1).unwrap(), &12);
a = vec![11i, 12, 13];
assert_eq!(a.as_slice().get(1).unwrap(), &12);
assert_eq!(a.get(1).unwrap(), &12);
}

#[test]
fn test_first() {
let mut a = vec![];
assert_eq!(a.as_slice().first(), None);
assert_eq!(a.first(), None);
a = vec![11i];
assert_eq!(a.as_slice().first().unwrap(), &11);
assert_eq!(a.first().unwrap(), &11);
a = vec![11i, 12];
assert_eq!(a.as_slice().first().unwrap(), &11);
assert_eq!(a.first().unwrap(), &11);
}

#[test]
Expand Down Expand Up @@ -1692,11 +1692,11 @@ mod tests {
#[test]
fn test_last() {
let mut a = vec![];
assert_eq!(a.as_slice().last(), None);
assert_eq!(a.last(), None);
a = vec![11i];
assert_eq!(a.as_slice().last().unwrap(), &11);
assert_eq!(a.last().unwrap(), &11);
a = vec![11i, 12];
assert_eq!(a.as_slice().last().unwrap(), &12);
assert_eq!(a.last().unwrap(), &12);
}

#[test]
Expand Down Expand Up @@ -1917,7 +1917,7 @@ mod tests {
let (min_size, max_opt) = it.size_hint();
assert_eq!(min_size, 1);
assert_eq!(max_opt.unwrap(), 1);
assert_eq!(it.next(), Some(v.as_slice().to_vec()));
assert_eq!(it.next(), Some(v.to_vec()));
assert_eq!(it.next(), None);
}
{
Expand All @@ -1926,7 +1926,7 @@ mod tests {
let (min_size, max_opt) = it.size_hint();
assert_eq!(min_size, 1);
assert_eq!(max_opt.unwrap(), 1);
assert_eq!(it.next(), Some(v.as_slice().to_vec()));
assert_eq!(it.next(), Some(v.to_vec()));
assert_eq!(it.next(), None);
}
{
Expand Down Expand Up @@ -2030,10 +2030,10 @@ mod tests {
assert!([].position_elem(&1i).is_none());

let v1 = vec![1i, 2, 3, 3, 2, 5];
assert_eq!(v1.as_slice().position_elem(&1), Some(0u));
assert_eq!(v1.as_slice().position_elem(&2), Some(1u));
assert_eq!(v1.as_slice().position_elem(&5), Some(5u));
assert!(v1.as_slice().position_elem(&4).is_none());
assert_eq!(v1.position_elem(&1), Some(0u));
assert_eq!(v1.position_elem(&2), Some(1u));
assert_eq!(v1.position_elem(&5), Some(5u));
assert!(v1.position_elem(&4).is_none());
}

#[test]
Expand Down Expand Up @@ -2104,13 +2104,13 @@ mod tests {
let mut v1 = v.clone();

v.sort();
assert!(v.as_slice().windows(2).all(|w| w[0] <= w[1]));
assert!(v.windows(2).all(|w| w[0] <= w[1]));

v1.sort_by(|a, b| a.cmp(b));
assert!(v1.as_slice().windows(2).all(|w| w[0] <= w[1]));
assert!(v1.windows(2).all(|w| w[0] <= w[1]));

v1.sort_by(|a, b| b.cmp(a));
assert!(v1.as_slice().windows(2).all(|w| w[0] >= w[1]));
assert!(v1.windows(2).all(|w| w[0] >= w[1]));
}
}

Expand Down Expand Up @@ -2149,7 +2149,7 @@ mod tests {
// will need to be ordered with increasing
// counts... i.e. exactly asserting that this sort is
// stable.
assert!(v.as_slice().windows(2).all(|w| w[0] <= w[1]));
assert!(v.windows(2).all(|w| w[0] <= w[1]));
}
}
}
Expand Down Expand Up @@ -2570,14 +2570,14 @@ mod tests {
assert!(a == [7i,2,3,4]);
let mut a = [1i,2,3,4,5];
let b = vec![5i,6,7,8,9,0];
assert_eq!(a.slice_mut(2, 4).move_from(b,1,6), 2);
assert_eq!(a[2..4].move_from(b,1,6), 2);
assert!(a == [1i,2,6,7,5]);
}

#[test]
fn test_reverse_part() {
let mut values = [1i,2,3,4,5];
values.slice_mut(1, 4).reverse();
values[1..4].reverse();
assert!(values == [1,4,3,2,5]);
}

Expand Down Expand Up @@ -2624,9 +2624,9 @@ mod tests {
fn test_bytes_set_memory() {
use slice::bytes::MutableByteVector;
let mut values = [1u8,2,3,4,5];
values.slice_mut(0, 5).set_memory(0xAB);
values[0..5].set_memory(0xAB);
assert!(values == [0xAB, 0xAB, 0xAB, 0xAB, 0xAB]);
values.slice_mut(2, 4).set_memory(0xFF);
values[2..4].set_memory(0xFF);
assert!(values == [0xAB, 0xAB, 0xFF, 0xFF, 0xAB]);
}

Expand Down Expand Up @@ -2884,7 +2884,7 @@ mod bench {
let xss: Vec<Vec<uint>> =
range(0, 100u).map(|i| range(0, i).collect()).collect();
b.iter(|| {
xss.as_slice().concat();
xss.concat();
});
}

Expand All @@ -2893,7 +2893,7 @@ mod bench {
let xss: Vec<Vec<uint>> =
range(0, 100u).map(|i| range(0, i).collect()).collect();
b.iter(|| {
xss.as_slice().connect(&0)
xss.connect(&0)
});
}

Expand All @@ -2910,15 +2910,15 @@ mod bench {
fn starts_with_same_vector(b: &mut Bencher) {
let vec: Vec<uint> = range(0, 100).collect();
b.iter(|| {
vec.as_slice().starts_with(vec.as_slice())
vec.starts_with(vec.as_slice())
})
}

#[bench]
fn starts_with_single_element(b: &mut Bencher) {
let vec: Vec<uint> = vec![0];
b.iter(|| {
vec.as_slice().starts_with(vec.as_slice())
vec.starts_with(vec.as_slice())
})
}

Expand All @@ -2928,23 +2928,23 @@ mod bench {
let mut match_vec: Vec<uint> = range(0, 99).collect();
match_vec.push(0);
b.iter(|| {
vec.as_slice().starts_with(match_vec.as_slice())
vec.starts_with(match_vec.as_slice())
})
}

#[bench]
fn ends_with_same_vector(b: &mut Bencher) {
let vec: Vec<uint> = range(0, 100).collect();
b.iter(|| {
vec.as_slice().ends_with(vec.as_slice())
vec.ends_with(vec.as_slice())
})
}

#[bench]
fn ends_with_single_element(b: &mut Bencher) {
let vec: Vec<uint> = vec![0];
b.iter(|| {
vec.as_slice().ends_with(vec.as_slice())
vec.ends_with(vec.as_slice())
})
}

Expand All @@ -2954,7 +2954,7 @@ mod bench {
let mut match_vec: Vec<uint> = range(0, 100).collect();
match_vec.as_mut_slice()[0] = 200;
b.iter(|| {
vec.as_slice().starts_with(match_vec.as_slice())
vec.starts_with(match_vec.as_slice())
})
}

Expand Down
Loading

0 comments on commit bedd810

Please sign in to comment.