Skip to content

Commit 7dd1bf0

Browse files
committed
auto merge of #17936 : TeXitoi/rust/remove-shootout-warnings, r=alexcrichton
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.
2 parents 1add4de + 5653b4d commit 7dd1bf0

6 files changed

+33
-31
lines changed

src/test/bench/shootout-chameneos-redux.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ struct CreatureInfo {
7272
fn show_color_list(set: Vec<Color>) -> String {
7373
let mut out = String::new();
7474
for col in set.iter() {
75-
out.push_char(' ');
75+
out.push(' ');
7676
out.push_str(col.to_string().as_slice());
7777
}
7878
out

src/test/bench/shootout-fasta.rs

+17-14
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,9 @@ impl<'a> Iterator<u8> for AAGen<'a> {
8585

8686
fn make_fasta<W: Writer, I: Iterator<u8>>(
8787
wr: &mut W, header: &str, mut it: I, mut n: uint)
88+
-> std::io::IoResult<()>
8889
{
89-
wr.write(header.as_bytes());
90+
try!(wr.write(header.as_bytes()));
9091
let mut line = [0u8, .. LINE_LENGTH + 1];
9192
while n > 0 {
9293
let nb = min(LINE_LENGTH, n);
@@ -95,11 +96,12 @@ fn make_fasta<W: Writer, I: Iterator<u8>>(
9596
}
9697
n -= nb;
9798
line[nb] = '\n' as u8;
98-
wr.write(line[..nb+1]);
99+
try!(wr.write(line[..nb+1]));
99100
}
101+
Ok(())
100102
}
101103

102-
fn run<W: Writer>(writer: &mut W) {
104+
fn run<W: Writer>(writer: &mut W) -> std::io::IoResult<()> {
103105
let args = os::args();
104106
let args = args.as_slice();
105107
let n = if os::getenv("RUST_BENCH").is_some() {
@@ -129,21 +131,22 @@ fn run<W: Writer>(writer: &mut W) {
129131
('g', 0.1975473066391),
130132
('t', 0.3015094502008)];
131133

132-
make_fasta(writer, ">ONE Homo sapiens alu\n",
133-
alu.as_bytes().iter().cycle().map(|c| *c), n * 2);
134-
make_fasta(writer, ">TWO IUB ambiguity codes\n",
135-
AAGen::new(rng, iub), n * 3);
136-
make_fasta(writer, ">THREE Homo sapiens frequency\n",
137-
AAGen::new(rng, homosapiens), n * 5);
134+
try!(make_fasta(writer, ">ONE Homo sapiens alu\n",
135+
alu.as_bytes().iter().cycle().map(|c| *c), n * 2));
136+
try!(make_fasta(writer, ">TWO IUB ambiguity codes\n",
137+
AAGen::new(rng, iub), n * 3));
138+
try!(make_fasta(writer, ">THREE Homo sapiens frequency\n",
139+
AAGen::new(rng, homosapiens), n * 5));
138140

139-
writer.flush();
141+
writer.flush()
140142
}
141143

142144
fn main() {
143-
if os::getenv("RUST_BENCH").is_some() {
145+
let res = if os::getenv("RUST_BENCH").is_some() {
144146
let mut file = BufferedWriter::new(File::create(&Path::new("./shootout-fasta.data")));
145-
run(&mut file);
147+
run(&mut file)
146148
} else {
147-
run(&mut io::stdout());
148-
}
149+
run(&mut io::stdout())
150+
};
151+
res.unwrap()
149152
}

src/test/bench/shootout-k-nucleotide.rs

+5-6
Original file line numberDiff line numberDiff line change
@@ -123,8 +123,8 @@ struct Entry {
123123
}
124124

125125
struct Table {
126-
count: uint,
127-
items: Vec<Option<Box<Entry>>> }
126+
items: Vec<Option<Box<Entry>>>
127+
}
128128

129129
struct Items<'a> {
130130
cur: Option<&'a Entry>,
@@ -134,7 +134,6 @@ struct Items<'a> {
134134
impl Table {
135135
fn new() -> Table {
136136
Table {
137-
count: 0,
138137
items: Vec::from_fn(TABLE_SIZE, |_| None),
139138
}
140139
}
@@ -165,7 +164,7 @@ impl Table {
165164
let index = key.hash() % (TABLE_SIZE as u64);
166165

167166
{
168-
if self.items.get(index as uint).is_none() {
167+
if self.items[index as uint].is_none() {
169168
let mut entry = box Entry {
170169
code: key,
171170
count: 0,
@@ -178,7 +177,7 @@ impl Table {
178177
}
179178

180179
{
181-
let entry = &mut *self.items.get_mut(index as uint).get_mut_ref();
180+
let entry = self.items.get_mut(index as uint).as_mut().unwrap();
182181
if entry.code == key {
183182
c.f(&mut **entry);
184183
return;
@@ -286,7 +285,7 @@ fn get_sequence<R: Buffer>(r: &mut R, key: &str) -> Vec<u8> {
286285
res.push_all(l.as_slice().trim().as_bytes());
287286
}
288287
for b in res.iter_mut() {
289-
*b = b.to_ascii().to_upper().to_byte();
288+
*b = b.to_ascii().to_uppercase().to_byte();
290289
}
291290
res
292291
}

src/test/bench/shootout-mandelbrot.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -109,8 +109,8 @@ fn mandelbrot<W: io::Writer>(w: uint, mut out: W) -> io::IoResult<()> {
109109

110110
for res in precalc_futures.into_iter() {
111111
let (rs, is) = res.unwrap();
112-
precalc_r.push_all_move(rs);
113-
precalc_i.push_all_move(is);
112+
precalc_r.extend(rs.into_iter());
113+
precalc_i.extend(is.into_iter());
114114
}
115115

116116
assert_eq!(precalc_r.len(), w);

src/test/bench/shootout-meteor.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -193,9 +193,9 @@ fn is_board_unfeasible(board: u64, masks: &Vec<Vec<Vec<u64>>>) -> bool {
193193
// Filter the masks that we can prove to result to unfeasible board.
194194
fn filter_masks(masks: &mut Vec<Vec<Vec<u64>>>) {
195195
for i in range(0, masks.len()) {
196-
for j in range(0, masks.get(i).len()) {
196+
for j in range(0, (*masks)[i].len()) {
197197
*masks.get_mut(i).get_mut(j) =
198-
masks.get(i).get(j).iter().map(|&m| m)
198+
(*masks)[i][j].iter().map(|&m| m)
199199
.filter(|&m| !is_board_unfeasible(m, masks))
200200
.collect();
201201
}
@@ -287,12 +287,12 @@ fn search(
287287
while board & (1 << i) != 0 && i < 50 {i += 1;}
288288
// the board is full: a solution is found.
289289
if i >= 50 {return handle_sol(&cur, data);}
290-
let masks_at = masks.get(i);
290+
let masks_at = &masks[i];
291291

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

307307
// launching the search in parallel on every masks at minimum
308308
// coordinate (0,0)
309-
for m in masks.get(0).iter().flat_map(|masks_pos| masks_pos.iter()) {
309+
for m in (*masks)[0].iter().flat_map(|masks_pos| masks_pos.iter()) {
310310
let masks = masks.clone();
311311
let tx = tx.clone();
312312
let m = *m;

src/test/bench/shootout-nbody.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -133,14 +133,14 @@ fn advance(bodies: &mut [Planet, ..N_BODIES], dt: f64, steps: int) {
133133

134134
fn energy(bodies: &[Planet, ..N_BODIES]) -> f64 {
135135
let mut e = 0.0;
136-
let mut bodies = bodies.as_slice();
136+
let mut bodies = bodies.iter();
137137
loop {
138-
let bi = match bodies.shift_ref() {
138+
let bi = match bodies.next() {
139139
Some(bi) => bi,
140140
None => break
141141
};
142142
e += (bi.vx * bi.vx + bi.vy * bi.vy + bi.vz * bi.vz) * bi.mass / 2.0;
143-
for bj in bodies.iter() {
143+
for bj in bodies.clone() {
144144
let dx = bi.x - bj.x;
145145
let dy = bi.y - bj.y;
146146
let dz = bi.z - bj.z;

0 commit comments

Comments
 (0)