Skip to content

Commit

Permalink
remove complicated qos test
Browse files Browse the repository at this point in the history
  • Loading branch information
lucarlig committed Mar 5, 2024
1 parent b2dabdb commit 454cc5e
Show file tree
Hide file tree
Showing 6 changed files with 108 additions and 680 deletions.
4 changes: 0 additions & 4 deletions lints/par_iter/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,6 @@ path = "ui/main.rs"
name = "par_iter_main2"
path = "ui/main2.rs"

[[example]]
name = "qos"
path = "ui/qos.rs"

[lints.clippy]
# GROUPS
perf = { level = "warn", priority = -1 }
Expand Down
50 changes: 50 additions & 0 deletions lints/par_iter/ui/main.fixed
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,13 @@ struct Pantheon {
tasks: Vec<String>,
}

#[derive(Debug, PartialEq)]
struct Case {
uid: u32,
mode: u32,
priority: u32,
}

fn main() {}

// should parallelize
Expand Down Expand Up @@ -268,3 +275,46 @@ fn mut_var_declared_in_closure() {
.collect();
println!("{:?}", doubled_numbers);
}

// no
fn request_request_filter() {
let case = Case {
uid: 1,
mode: 10,
priority: 20,
};

let high_qos_cases = vec![
Case {
uid: 2,
mode: 15,
priority: 25,
},
Case {
uid: 1,
mode: 5,
priority: 30,
},
Case {
uid: 3,
mode: 20,
priority: 10,
},
];

let mut down_grade_case = &case;
let mut swap_case_index_opt: Option<usize> = None;
(high_qos_cases.iter().enumerate())
.filter(|(i, swap_case)| {
down_grade_case.uid == swap_case.uid
&& (down_grade_case.mode < swap_case.mode
|| down_grade_case.priority < swap_case.priority)
})
.for_each(|(i, swap_case)| {
down_grade_case = swap_case;
swap_case_index_opt = Some(i)
});

println!("Downgrade case: {:?}", down_grade_case);
println!("Swap case index: {:?}", swap_case_index_opt);
}
50 changes: 50 additions & 0 deletions lints/par_iter/ui/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,13 @@ struct Pantheon {
tasks: Vec<String>,
}

#[derive(Debug, PartialEq)]
struct Case {
uid: u32,
mode: u32,
priority: u32,
}

fn main() {}

// should parallelize
Expand Down Expand Up @@ -268,3 +275,46 @@ fn mut_var_declared_in_closure() {
.collect();
println!("{:?}", doubled_numbers);
}

// no
fn request_request_filter() {
let case = Case {
uid: 1,
mode: 10,
priority: 20,
};

let high_qos_cases = vec![
Case {
uid: 2,
mode: 15,
priority: 25,
},
Case {
uid: 1,
mode: 5,
priority: 30,
},
Case {
uid: 3,
mode: 20,
priority: 10,
},
];

let mut down_grade_case = &case;
let mut swap_case_index_opt: Option<usize> = None;
(high_qos_cases.iter().enumerate())
.filter(|(i, swap_case)| {
down_grade_case.uid == swap_case.uid
&& (down_grade_case.mode < swap_case.mode
|| down_grade_case.priority < swap_case.priority)
})
.for_each(|(i, swap_case)| {
down_grade_case = swap_case;
swap_case_index_opt = Some(i)
});

println!("Downgrade case: {:?}", down_grade_case);
println!("Swap case index: {:?}", swap_case_index_opt);
}
16 changes: 8 additions & 8 deletions lints/par_iter/ui/main.stderr
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
error: found iterator that can be parallelized
--> $DIR/main.rs:27:5
--> $DIR/main.rs:34:5
|
LL | (0..100).into_iter().for_each(|x| println!("{:?}", x));
| ^^^^^^^^^^^^^^^^^^^^ help: try using a parallel iterator: `(0..100).into_par_iter()`
Expand All @@ -8,7 +8,7 @@ LL | (0..100).into_iter().for_each(|x| println!("{:?}", x));
= help: to override `-D warnings` add `#[allow(par_iter)]`

error: found iterator that can be parallelized
--> $DIR/main.rs:51:5
--> $DIR/main.rs:58:5
|
LL | / (0..100)
LL | | .into_iter()
Expand All @@ -21,37 +21,37 @@ LL + .into_par_iter()
|

error: found iterator that can be parallelized
--> $DIR/main.rs:86:5
--> $DIR/main.rs:93:5
|
LL | list.into_iter().for_each(|x| println!("{:?}", x));
| ^^^^^^^^^^^^^^^^ help: try using a parallel iterator: `list.into_par_iter()`

error: found iterator that can be parallelized
--> $DIR/main.rs:102:5
--> $DIR/main.rs:109:5
|
LL | (0..10).into_iter().for_each(|x| {
| ^^^^^^^^^^^^^^^^^^^ help: try using a parallel iterator: `(0..10).into_par_iter()`

error: found iterator that can be parallelized
--> $DIR/main.rs:185:5
--> $DIR/main.rs:192:5
|
LL | data.iter()
| ^^^^^^^^^^^ help: try using a parallel iterator: `data.par_iter()`

error: found iterator that can be parallelized
--> $DIR/main.rs:212:5
--> $DIR/main.rs:219:5
|
LL | numbers.iter().enumerate().for_each(|t| {
| ^^^^^^^^^^^^^^ help: try using a parallel iterator: `numbers.par_iter()`

error: found iterator that can be parallelized
--> $DIR/main.rs:253:30
--> $DIR/main.rs:260:30
|
LL | let names: Vec<String> = people.iter().map(|p| p.name.clone()).collect();
| ^^^^^^^^^^^^^ help: try using a parallel iterator: `people.par_iter()`

error: found iterator that can be parallelized
--> $DIR/main.rs:261:37
--> $DIR/main.rs:268:37
|
LL | let doubled_numbers: Vec<i32> = numbers
| _____________________________________^
Expand Down
Loading

0 comments on commit 454cc5e

Please sign in to comment.