From bb79903938691220641a9afcdb73b9bce7ca522b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=A0=E6=9E=97=E4=BC=9F?= Date: Wed, 11 Jan 2023 09:32:07 +0000 Subject: [PATCH] Fix clippy issue for benches crate (#6806) # Objective - https://github.com/bevyengine/bevy/pull/3505 marked `S-Adopt-Me` , this pr is to continue his work. ## Solution - run `cargo clippy --workspace --all-targets --all-features -- -Aclippy::type_complexity -Wclippy::doc_markdown -Wclippy::redundant_else -Wclippy::match_same_arms -Wclippy::semicolon_if_nothing_returned -Wclippy::explicit_iter_loop -Wclippy::map_flatten -Dwarnings` under benches dir. - fix issue according to suggestion. --- .../benches/bevy_ecs/components/archetype_updates.rs | 2 +- benches/benches/bevy_ecs/scheduling/schedule.rs | 8 ++++---- benches/benches/bevy_ecs/scheduling/stages.rs | 6 +++--- benches/benches/bevy_ecs/world/commands.rs | 9 ++------- benches/benches/bevy_ecs/world/world_get.rs | 2 +- benches/benches/bevy_reflect/list.rs | 4 ++-- benches/benches/bevy_reflect/map.rs | 10 +++++----- benches/benches/bevy_tasks/iter.rs | 12 ++++++------ 8 files changed, 24 insertions(+), 29 deletions(-) diff --git a/benches/benches/bevy_ecs/components/archetype_updates.rs b/benches/benches/bevy_ecs/components/archetype_updates.rs index 7574104c38..8cb4c5552d 100644 --- a/benches/benches/bevy_ecs/components/archetype_updates.rs +++ b/benches/benches/bevy_ecs/components/archetype_updates.rs @@ -109,7 +109,7 @@ pub fn added_archetypes(criterion: &mut Criterion) { stage.run(&mut world); }, criterion::BatchSize::LargeInput, - ) + ); }, ); } diff --git a/benches/benches/bevy_ecs/scheduling/schedule.rs b/benches/benches/bevy_ecs/scheduling/schedule.rs index 49de37079b..55887fb643 100644 --- a/benches/benches/bevy_ecs/scheduling/schedule.rs +++ b/benches/benches/bevy_ecs/scheduling/schedule.rs @@ -110,11 +110,11 @@ pub fn build_schedule(criterion: &mut Criterion) { // Not particularly realistic but this can be refined later. for i in 0..graph_size { let mut sys = empty_system.label(labels[i]).before(DummyLabel); - for a in 0..i { - sys = sys.after(labels[a]); + for label in labels.iter().take(i) { + sys = sys.after(*label); } - for b in i + 1..graph_size { - sys = sys.before(labels[b]); + for label in &labels[i + 1..graph_size] { + sys = sys.before(*label); } app.add_system(sys); } diff --git a/benches/benches/bevy_ecs/scheduling/stages.rs b/benches/benches/bevy_ecs/scheduling/stages.rs index 0f258f4f99..fec9ba5eab 100644 --- a/benches/benches/bevy_ecs/scheduling/stages.rs +++ b/benches/benches/bevy_ecs/scheduling/stages.rs @@ -58,7 +58,7 @@ pub fn empty_systems(criterion: &mut Criterion) { }); }); } - group.finish() + group.finish(); } pub fn busy_systems(criterion: &mut Criterion) { @@ -107,7 +107,7 @@ pub fn busy_systems(criterion: &mut Criterion) { ); } } - group.finish() + group.finish(); } pub fn contrived(criterion: &mut Criterion) { @@ -158,5 +158,5 @@ pub fn contrived(criterion: &mut Criterion) { ); } } - group.finish() + group.finish(); } diff --git a/benches/benches/bevy_ecs/world/commands.rs b/benches/benches/bevy_ecs/world/commands.rs index 41f9bbe29e..6a55cb5ea8 100644 --- a/benches/benches/bevy_ecs/world/commands.rs +++ b/benches/benches/bevy_ecs/world/commands.rs @@ -61,7 +61,6 @@ pub fn spawn_commands(criterion: &mut Criterion) { entity.despawn(); } } - drop(commands); command_queue.apply(&mut world); }); }); @@ -82,7 +81,7 @@ pub fn insert_commands(criterion: &mut Criterion) { group.measurement_time(std::time::Duration::from_secs(4)); let entity_count = 10_000; - group.bench_function(format!("insert"), |bencher| { + group.bench_function("insert", |bencher| { let mut world = World::default(); let mut command_queue = CommandQueue::default(); let mut entities = Vec::new(); @@ -97,11 +96,10 @@ pub fn insert_commands(criterion: &mut Criterion) { .entity(*entity) .insert((Matrix::default(), Vec3::default())); } - drop(commands); command_queue.apply(&mut world); }); }); - group.bench_function(format!("insert_batch"), |bencher| { + group.bench_function("insert_batch", |bencher| { let mut world = World::default(); let mut command_queue = CommandQueue::default(); let mut entities = Vec::new(); @@ -116,7 +114,6 @@ pub fn insert_commands(criterion: &mut Criterion) { values.push((*entity, (Matrix::default(), Vec3::default()))); } commands.insert_or_spawn_batch(values); - drop(commands); command_queue.apply(&mut world); }); }); @@ -160,7 +157,6 @@ pub fn fake_commands(criterion: &mut Criterion) { commands.add(FakeCommandB(0)); } } - drop(commands); command_queue.apply(&mut world); }); }); @@ -203,7 +199,6 @@ pub fn sized_commands_impl(criterion: &mut Criterion) { for _ in 0..command_count { commands.add(T::default()); } - drop(commands); command_queue.apply(&mut world); }); }); diff --git a/benches/benches/bevy_ecs/world/world_get.rs b/benches/benches/bevy_ecs/world/world_get.rs index 536b5a7b8b..4fc7ed5104 100644 --- a/benches/benches/bevy_ecs/world/world_get.rs +++ b/benches/benches/bevy_ecs/world/world_get.rs @@ -273,7 +273,7 @@ pub fn query_get_component_simple(criterion: &mut Criterion) { bencher.iter(|| { for _x in 0..100000 { - let mut a = unsafe { query.get_unchecked(&mut world, entity).unwrap() }; + let mut a = unsafe { query.get_unchecked(&world, entity).unwrap() }; a.0 += 1.0; } }); diff --git a/benches/benches/bevy_reflect/list.rs b/benches/benches/bevy_reflect/list.rs index 3c48dd22e4..0c366e0540 100644 --- a/benches/benches/bevy_reflect/list.rs +++ b/benches/benches/bevy_reflect/list.rs @@ -44,7 +44,7 @@ fn list_apply( let f_base = f_base(size); let patch = f_patch(size); bencher.iter_batched( - || f_base(), + f_base, |mut base| base.apply(black_box(&patch)), BatchSize::SmallInput, ); @@ -58,7 +58,7 @@ fn concrete_list_apply(criterion: &mut Criterion) { group.warm_up_time(WARM_UP_TIME); group.measurement_time(MEASUREMENT_TIME); - let empty_base = |_: usize| || Vec::::new(); + let empty_base = |_: usize| Vec::::new; let full_base = |size: usize| move || iter::repeat(0).take(size).collect::>(); let patch = |size: usize| iter::repeat(1).take(size).collect::>(); diff --git a/benches/benches/bevy_reflect/map.rs b/benches/benches/bevy_reflect/map.rs index b5c8a95eee..b27a096d3d 100644 --- a/benches/benches/bevy_reflect/map.rs +++ b/benches/benches/bevy_reflect/map.rs @@ -60,7 +60,7 @@ fn concrete_map_apply(criterion: &mut Criterion) { group.warm_up_time(WARM_UP_TIME); group.measurement_time(MEASUREMENT_TIME); - let empty_base = |_: usize| || HashMap::::default(); + let empty_base = |_: usize| HashMap::::default; let key_range_base = |size: usize| { move || { @@ -136,7 +136,7 @@ fn dynamic_map_apply(criterion: &mut Criterion) { group.warm_up_time(WARM_UP_TIME); group.measurement_time(MEASUREMENT_TIME); - let empty_base = |_: usize| || DynamicMap::default(); + let empty_base = |_: usize| DynamicMap::default; let key_range_base = |size: usize| { move || { @@ -240,8 +240,8 @@ fn dynamic_map_get(criterion: &mut Criterion) { } bencher.iter(|| { - for i in 0..size { - let key = black_box(&keys[i]); + for key in keys.iter().take(size) { + let key = black_box(key); assert!(map.get(key).is_some()); } }); @@ -262,7 +262,7 @@ fn dynamic_map_insert(criterion: &mut Criterion) { &size, |bencher, &size| { bencher.iter_batched( - || DynamicMap::default(), + DynamicMap::default, |mut map| { for i in 0..size as u64 { let key = black_box(i); diff --git a/benches/benches/bevy_tasks/iter.rs b/benches/benches/bevy_tasks/iter.rs index 74b043f9a2..ee1babf4e2 100644 --- a/benches/benches/bevy_tasks/iter.rs +++ b/benches/benches/bevy_tasks/iter.rs @@ -28,7 +28,7 @@ fn bench_overhead(c: &mut Criterion) { c.bench_function("overhead_iter", |b| { b.iter(|| { v.iter_mut().for_each(noop); - }) + }); }); let mut v = (0..10000).collect::>(); @@ -41,7 +41,7 @@ fn bench_overhead(c: &mut Criterion) { |b, _| { b.iter(|| { ParChunksMut(v.chunks_mut(100)).for_each(&pool, noop); - }) + }); }, ); } @@ -63,7 +63,7 @@ fn bench_for_each(c: &mut Criterion) { busy_work(10000); *x *= *x; }); - }) + }); }); let mut v = (0..10000).collect::>(); @@ -79,7 +79,7 @@ fn bench_for_each(c: &mut Criterion) { busy_work(10000); *x *= *x; }); - }) + }); }, ); } @@ -109,7 +109,7 @@ fn bench_many_maps(c: &mut Criterion) { .map(|x| busy_doubles(x, 1000)) .map(|x| busy_doubles(x, 1000)) .for_each(drop); - }) + }); }); let v = (0..10000).collect::>(); @@ -133,7 +133,7 @@ fn bench_many_maps(c: &mut Criterion) { .map(|x| busy_doubles(x, 1000)) .map(|x| busy_doubles(x, 1000)) .for_each(&pool, drop); - }) + }); }, ); }