Skip to content

Commit 146000b

Browse files
committed
Clippy in rayon-demo
1 parent c2b9cdd commit 146000b

File tree

13 files changed

+67
-70
lines changed

13 files changed

+67
-70
lines changed

rayon-demo/src/life/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const USAGE: &'static str = "
1+
const USAGE: &str = "
22
Usage: life bench [--size N] [--gens N]
33
life play [--size N] [--gens N] [--fps N]
44
life --help
@@ -68,8 +68,8 @@ impl Board {
6868
board: new_board,
6969
born: Arc::new(born),
7070
survive: Arc::new(survive),
71-
rows: rows,
72-
cols: cols,
71+
rows,
72+
cols,
7373
}
7474
}
7575

rayon-demo/src/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ extern crate winapi; // life
6060
#[cfg(test)]
6161
extern crate test;
6262

63-
const USAGE: &'static str = "
63+
const USAGE: &str = "
6464
Usage: rayon-demo bench
6565
rayon-demo <demo-name> [ options ]
6666
rayon-demo --help

rayon-demo/src/matmul/mod.rs

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const USAGE: &'static str = "
1+
const USAGE: &str = "
22
Usage: matmul bench [--size N]
33
matmul --help
44
Parallel matrix multiplication.
@@ -54,7 +54,7 @@ struct SplayedBitsCounter {
5454

5555
impl SplayedBitsCounter {
5656
fn new(max: usize) -> Self {
57-
SplayedBitsCounter { value: 0, max: max }
57+
SplayedBitsCounter { value: 0, max }
5858
}
5959
}
6060

@@ -63,10 +63,10 @@ impl Iterator for SplayedBitsCounter {
6363

6464
fn next(&mut self) -> Option<usize> {
6565
// Return only odd bits.
66-
let prev = self.value & 0x55555555;
66+
let prev = self.value & 0x5555_5555;
6767
if prev < self.max {
6868
// Set all even bits.
69-
self.value |= 0xaaaaaaaa;
69+
self.value |= 0xaaaa_aaaa;
7070
// Add one, carrying through even bits.
7171
self.value += 1;
7272
Some(prev)
@@ -101,9 +101,9 @@ pub fn seq_matmulz(a: &[f32], b: &[f32], dest: &mut [f32]) {
101101
// Multiply in morton order
102102
// D[i,j] = sum for all k A[i,k] * B[k,j]
103103
let n = dest.len();
104-
for ij in 0..n {
105-
let i = ij & 0xaaaaaaaa;
106-
let j = ij & 0x55555555;
104+
for (ij, d) in dest.iter_mut().enumerate() {
105+
let i = ij & 0xaaaa_aaaa;
106+
let j = ij & 0x5555_5555;
107107
let mut sum = 0.0;
108108
for k in SplayedBitsCounter::new(n) {
109109
// sum += a[i, k] * b[k, j];
@@ -113,14 +113,14 @@ pub fn seq_matmulz(a: &[f32], b: &[f32], dest: &mut [f32]) {
113113
a.get_unchecked(i | k) * b.get_unchecked(k << 1 | j)
114114
};
115115
}
116-
dest[ij] = sum;
116+
*d = sum;
117117
}
118118
}
119119

120120
const MULT_CHUNK: usize = 1 * 1024;
121121
const LINEAR_CHUNK: usize = 64 * 1024;
122122

123-
fn quarter_chunks<'a>(v: &'a [f32]) -> (&'a [f32], &'a [f32], &'a [f32], &'a [f32]) {
123+
fn quarter_chunks(v: &[f32]) -> (&[f32], &[f32], &[f32], &[f32]) {
124124
let mid = v.len() / 2;
125125
let quarter = mid / 2;
126126
let (left, right) = v.split_at(mid);
@@ -129,9 +129,7 @@ fn quarter_chunks<'a>(v: &'a [f32]) -> (&'a [f32], &'a [f32], &'a [f32], &'a [f3
129129
(a, b, c, d)
130130
}
131131

132-
fn quarter_chunks_mut<'a>(
133-
v: &'a mut [f32],
134-
) -> (&'a mut [f32], &'a mut [f32], &'a mut [f32], &'a mut [f32]) {
132+
fn quarter_chunks_mut(v: &mut [f32]) -> (&mut [f32], &mut [f32], &mut [f32], &mut [f32]) {
135133
let mid = v.len() / 2;
136134
let quarter = mid / 2;
137135
let (left, right) = v.split_at_mut(mid);
@@ -390,15 +388,15 @@ fn timed_matmul<F: FnOnce(&[f32], &[f32], &mut [f32])>(size: usize, f: F, name:
390388
let start = Instant::now();
391389
f(&a[..], &b[..], &mut dest[..]);
392390
let dur = Instant::now() - start;
393-
let nanos = dur.subsec_nanos() as u64 + dur.as_secs() * 1_000_000_000u64;
391+
let nanos = u64::from(dur.subsec_nanos()) + dur.as_secs() * 1_000_000_000u64;
394392
println!(
395393
"{}:\t{}x{} matrix: {} s",
396394
name,
397395
size,
398396
size,
399397
nanos as f32 / 1e9f32
400398
);
401-
return nanos;
399+
nanos
402400
}
403401

404402
pub fn main(args: &[String]) {

rayon-demo/src/mergesort/mod.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use rand::distributions::Standard;
22
use rand::Rng;
33

4-
const USAGE: &'static str = "
4+
const USAGE: &str = "
55
Usage: mergesort bench [--size N]
66
mergesort --help
77
@@ -213,7 +213,7 @@ pub fn is_sorted<T: Send + Ord>(v: &mut [T]) -> bool {
213213
}
214214
let (a, b) = v.split_at_mut(mid);
215215
let (left, right) = rayon::join(|| is_sorted(a), || is_sorted(b));
216-
return left && right;
216+
left && right
217217
}
218218

219219
fn default_vec(n: usize) -> Vec<u32> {
@@ -227,13 +227,13 @@ fn timed_sort<F: FnOnce(&mut [u32])>(n: usize, f: F, name: &str) -> u64 {
227227
let start = Instant::now();
228228
f(&mut v[..]);
229229
let dur = Instant::now() - start;
230-
let nanos = dur.subsec_nanos() as u64 + dur.as_secs() * 1_000_000_000u64;
230+
let nanos = u64::from(dur.subsec_nanos()) + dur.as_secs() * 1_000_000_000u64;
231231
println!("{}: sorted {} ints: {} s", name, n, nanos as f32 / 1e9f32);
232232

233233
// Check correctness
234234
assert!(is_sorted(&mut v[..]));
235235

236-
return nanos;
236+
nanos
237237
}
238238

239239
pub fn main(args: &[String]) {

rayon-demo/src/nbody/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ mod visualize;
88
use self::nbody::NBodyBenchmark;
99
use self::visualize::visualize_benchmarks;
1010

11-
const USAGE: &'static str = "
11+
const USAGE: &str = "
1212
Usage: nbody bench [--mode MODE --bodies N --ticks N]
1313
nbody visualize [--mode MODE --bodies N]
1414
nbody --help

rayon-demo/src/nbody/nbody.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,9 +76,9 @@ impl NBodyBenchmark {
7676
};
7777

7878
Body {
79-
position: position,
80-
velocity: velocity,
81-
velocity2: velocity2,
79+
position,
80+
velocity,
81+
velocity2,
8282
}
8383
})
8484
.collect();

rayon-demo/src/quicksort/mod.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#![allow(non_camel_case_types)]
22

3-
const USAGE: &'static str = "
3+
const USAGE: &str = "
44
Usage: quicksort bench [options]
55
quicksort --help
66
@@ -118,13 +118,13 @@ fn timed_sort<F: FnOnce(&mut [u32])>(n: usize, f: F, name: &str) -> u64 {
118118
let start = Instant::now();
119119
f(&mut v[..]);
120120
let dur = Instant::now() - start;
121-
let nanos = dur.subsec_nanos() as u64 + dur.as_secs() * 1_000_000_000u64;
121+
let nanos = u64::from(dur.subsec_nanos()) + dur.as_secs() * 1_000_000_000u64;
122122
println!("{}: sorted {} ints: {} s", name, n, nanos as f32 / 1e9f32);
123123

124124
// Check correctness
125-
assert!(is_sorted(&mut v[..]));
125+
assert!(is_sorted(&v[..]));
126126

127-
return nanos;
127+
nanos
128128
}
129129

130130
pub fn main(args: &[String]) {

rayon-demo/src/sieve/mod.rs

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const USAGE: &'static str = "
1+
const USAGE: &str = "
22
Usage: sieve bench
33
sieve --help
44
@@ -48,28 +48,28 @@ const CHUNK_SIZE: usize = 100_000;
4848

4949
// Number of Primes < 10^n
5050
// https://oeis.org/A006880
51-
const NUM_PRIMES: &'static [usize] = &[
51+
const NUM_PRIMES: &[usize] = &[
5252
0, // primes in 0..10^0
5353
4, // primes in 0..10^1
5454
25, // etc
5555
168,
56-
1229,
57-
9592,
58-
78498,
59-
664579,
60-
5761455,
61-
50847534,
62-
455052511,
63-
4118054813,
64-
37607912018,
65-
346065536839,
66-
3204941750802,
67-
29844570422669,
68-
279238341033925,
69-
2623557157654233,
70-
24739954287740860,
71-
234057667276344607,
72-
2220819602560918840,
56+
1_229,
57+
9_592,
58+
78_498,
59+
664_579,
60+
5_761_455,
61+
50_847_534,
62+
455_052_511,
63+
4_118_054_813,
64+
37_607_912_018,
65+
346_065_536_839,
66+
3_204_941_750_802,
67+
29_844_570_422_669,
68+
279_238_341_033_925,
69+
2_623_557_157_654_233,
70+
24_739_954_287_740_860,
71+
234_057_667_276_344_607,
72+
2_220_819_602_560_918_840,
7373
];
7474

7575
// For all of these sieves, sieve[i]==true -> 2*i+1 is prime
@@ -149,7 +149,7 @@ fn update_chunk(low: &[bool], chunk: &mut [bool], base: usize) {
149149

150150
let pm = if pp < base {
151151
// p² is too small - find the first odd multiple that's in range
152-
((base + p - 1) / p | 1) * p
152+
(((base + p - 1) / p) | 1) * p
153153
} else {
154154
pp
155155
};

rayon-demo/src/tsp/graph.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ pub struct Graph {
1515
impl Graph {
1616
pub fn new(num_nodes: usize) -> Graph {
1717
Graph {
18-
num_nodes: num_nodes,
18+
num_nodes,
1919
weights: iter::repeat(Weight::max())
2020
.take(num_nodes * num_nodes)
2121
.collect(),
@@ -58,9 +58,9 @@ impl Graph {
5858
pub fn edges<'a>(&'a self, source: Node) -> impl Iterator<Item = Edge> + 'a {
5959
self.all_nodes().filter_map(move |target| {
6060
self.edge_weight(source, target).map(|weight| Edge {
61-
source: source,
62-
target: target,
63-
weight: weight,
61+
source,
62+
target,
63+
weight,
6464
})
6565
})
6666
}
@@ -73,10 +73,10 @@ pub struct Node {
7373

7474
impl Node {
7575
pub fn new(index: usize) -> Node {
76-
Node { index: index }
76+
Node { index }
7777
}
7878

79-
pub fn index(&self) -> usize {
79+
pub fn index(self) -> usize {
8080
self.index
8181
}
8282
}

rayon-demo/src/tsp/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ mod weight;
2222
use self::graph::{Graph, Node};
2323
use self::solver::SolverCx;
2424

25-
const USAGE: &'static str = "
25+
const USAGE: &str = "
2626
Usage: tsp bench [--seq-threshold N] [--from N] <datafile>
2727
2828
Parallel traveling salesman problem solver. Data input is expected to
@@ -91,7 +91,7 @@ fn run_solver(datafile: &Path, seq_threshold: usize, from: usize) -> Result<(),
9191
println!("Total search time: {:?}", par_time);
9292
if let Some(path) = path {
9393
println!("Cheapest path cost: {}", weight.to_usize());
94-
let mut output = format!("Cheapest path:");
94+
let mut output = "Cheapest path:".to_string();
9595
for node in path {
9696
output.push_str(&format!(" {}", node.index()));
9797
}

0 commit comments

Comments
 (0)