Skip to content

Commit

Permalink
auto merge of #17936 : TeXitoi/rust/remove-shootout-warnings, r=alexc…
Browse files Browse the repository at this point in the history
…richton

Only one warning remain, and I can't find a way to remove it without doing more bound checks:

```
shootout-nbody.rs:105:36: 105:51 warning: use of deprecated item: use iter_mut, #[warn(deprecated)] on by default
shootout-nbody.rs:105             let bi = match b_slice.mut_shift_ref() {
```

using `split_at_mut` may be an option, but it will do more bound checking.

If anyone have an idea, I'll update this PR.
  • Loading branch information
bors committed Oct 11, 2014
2 parents 1add4de + 5653b4d commit 7dd1bf0
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 31 deletions.
2 changes: 1 addition & 1 deletion src/test/bench/shootout-chameneos-redux.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ struct CreatureInfo {
fn show_color_list(set: Vec<Color>) -> String {
let mut out = String::new();
for col in set.iter() {
out.push_char(' ');
out.push(' ');
out.push_str(col.to_string().as_slice());
}
out
Expand Down
31 changes: 17 additions & 14 deletions src/test/bench/shootout-fasta.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,9 @@ impl<'a> Iterator<u8> for AAGen<'a> {

fn make_fasta<W: Writer, I: Iterator<u8>>(
wr: &mut W, header: &str, mut it: I, mut n: uint)
-> std::io::IoResult<()>
{
wr.write(header.as_bytes());
try!(wr.write(header.as_bytes()));
let mut line = [0u8, .. LINE_LENGTH + 1];
while n > 0 {
let nb = min(LINE_LENGTH, n);
Expand All @@ -95,11 +96,12 @@ fn make_fasta<W: Writer, I: Iterator<u8>>(
}
n -= nb;
line[nb] = '\n' as u8;
wr.write(line[..nb+1]);
try!(wr.write(line[..nb+1]));
}
Ok(())
}

fn run<W: Writer>(writer: &mut W) {
fn run<W: Writer>(writer: &mut W) -> std::io::IoResult<()> {
let args = os::args();
let args = args.as_slice();
let n = if os::getenv("RUST_BENCH").is_some() {
Expand Down Expand Up @@ -129,21 +131,22 @@ fn run<W: Writer>(writer: &mut W) {
('g', 0.1975473066391),
('t', 0.3015094502008)];

make_fasta(writer, ">ONE Homo sapiens alu\n",
alu.as_bytes().iter().cycle().map(|c| *c), n * 2);
make_fasta(writer, ">TWO IUB ambiguity codes\n",
AAGen::new(rng, iub), n * 3);
make_fasta(writer, ">THREE Homo sapiens frequency\n",
AAGen::new(rng, homosapiens), n * 5);
try!(make_fasta(writer, ">ONE Homo sapiens alu\n",
alu.as_bytes().iter().cycle().map(|c| *c), n * 2));
try!(make_fasta(writer, ">TWO IUB ambiguity codes\n",
AAGen::new(rng, iub), n * 3));
try!(make_fasta(writer, ">THREE Homo sapiens frequency\n",
AAGen::new(rng, homosapiens), n * 5));

writer.flush();
writer.flush()
}

fn main() {
if os::getenv("RUST_BENCH").is_some() {
let res = if os::getenv("RUST_BENCH").is_some() {
let mut file = BufferedWriter::new(File::create(&Path::new("./shootout-fasta.data")));
run(&mut file);
run(&mut file)
} else {
run(&mut io::stdout());
}
run(&mut io::stdout())
};
res.unwrap()
}
11 changes: 5 additions & 6 deletions src/test/bench/shootout-k-nucleotide.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,8 @@ struct Entry {
}

struct Table {
count: uint,
items: Vec<Option<Box<Entry>>> }
items: Vec<Option<Box<Entry>>>
}

struct Items<'a> {
cur: Option<&'a Entry>,
Expand All @@ -134,7 +134,6 @@ struct Items<'a> {
impl Table {
fn new() -> Table {
Table {
count: 0,
items: Vec::from_fn(TABLE_SIZE, |_| None),
}
}
Expand Down Expand Up @@ -165,7 +164,7 @@ impl Table {
let index = key.hash() % (TABLE_SIZE as u64);

{
if self.items.get(index as uint).is_none() {
if self.items[index as uint].is_none() {
let mut entry = box Entry {
code: key,
count: 0,
Expand All @@ -178,7 +177,7 @@ impl Table {
}

{
let entry = &mut *self.items.get_mut(index as uint).get_mut_ref();
let entry = self.items.get_mut(index as uint).as_mut().unwrap();
if entry.code == key {
c.f(&mut **entry);
return;
Expand Down Expand Up @@ -286,7 +285,7 @@ fn get_sequence<R: Buffer>(r: &mut R, key: &str) -> Vec<u8> {
res.push_all(l.as_slice().trim().as_bytes());
}
for b in res.iter_mut() {
*b = b.to_ascii().to_upper().to_byte();
*b = b.to_ascii().to_uppercase().to_byte();
}
res
}
Expand Down
4 changes: 2 additions & 2 deletions src/test/bench/shootout-mandelbrot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,8 @@ fn mandelbrot<W: io::Writer>(w: uint, mut out: W) -> io::IoResult<()> {

for res in precalc_futures.into_iter() {
let (rs, is) = res.unwrap();
precalc_r.push_all_move(rs);
precalc_i.push_all_move(is);
precalc_r.extend(rs.into_iter());
precalc_i.extend(is.into_iter());
}

assert_eq!(precalc_r.len(), w);
Expand Down
10 changes: 5 additions & 5 deletions src/test/bench/shootout-meteor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -193,9 +193,9 @@ fn is_board_unfeasible(board: u64, masks: &Vec<Vec<Vec<u64>>>) -> bool {
// Filter the masks that we can prove to result to unfeasible board.
fn filter_masks(masks: &mut Vec<Vec<Vec<u64>>>) {
for i in range(0, masks.len()) {
for j in range(0, masks.get(i).len()) {
for j in range(0, (*masks)[i].len()) {
*masks.get_mut(i).get_mut(j) =
masks.get(i).get(j).iter().map(|&m| m)
(*masks)[i][j].iter().map(|&m| m)
.filter(|&m| !is_board_unfeasible(m, masks))
.collect();
}
Expand Down Expand Up @@ -287,12 +287,12 @@ fn search(
while board & (1 << i) != 0 && i < 50 {i += 1;}
// the board is full: a solution is found.
if i >= 50 {return handle_sol(&cur, data);}
let masks_at = masks.get(i);
let masks_at = &masks[i];

// for every unused piece
for id in range(0u, 10).filter(|id| board & (1 << (id + 50)) == 0) {
// for each mask that fits on the board
for m in masks_at.get(id).iter().filter(|&m| board & *m == 0) {
for m in masks_at[id].iter().filter(|&m| board & *m == 0) {
// This check is too costly.
//if is_board_unfeasible(board | m, masks) {continue;}
search(masks, board | *m, i + 1, Cons(*m, &cur), data);
Expand All @@ -306,7 +306,7 @@ fn par_search(masks: Vec<Vec<Vec<u64>>>) -> Data {

// launching the search in parallel on every masks at minimum
// coordinate (0,0)
for m in masks.get(0).iter().flat_map(|masks_pos| masks_pos.iter()) {
for m in (*masks)[0].iter().flat_map(|masks_pos| masks_pos.iter()) {
let masks = masks.clone();
let tx = tx.clone();
let m = *m;
Expand Down
6 changes: 3 additions & 3 deletions src/test/bench/shootout-nbody.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,14 +133,14 @@ fn advance(bodies: &mut [Planet, ..N_BODIES], dt: f64, steps: int) {

fn energy(bodies: &[Planet, ..N_BODIES]) -> f64 {
let mut e = 0.0;
let mut bodies = bodies.as_slice();
let mut bodies = bodies.iter();
loop {
let bi = match bodies.shift_ref() {
let bi = match bodies.next() {
Some(bi) => bi,
None => break
};
e += (bi.vx * bi.vx + bi.vy * bi.vy + bi.vz * bi.vz) * bi.mass / 2.0;
for bj in bodies.iter() {
for bj in bodies.clone() {
let dx = bi.x - bj.x;
let dy = bi.y - bj.y;
let dz = bi.z - bj.z;
Expand Down

0 comments on commit 7dd1bf0

Please sign in to comment.