Skip to content

Commit

Permalink
Fix clippy::iter_with_drain (bevyengine#6485)
Browse files Browse the repository at this point in the history
# Objective

Fixes bevyengine#6483.

- Fix the [`clippy::iter_with_drain`](https://rust-lang.github.io/rust-clippy/master/index.html#iter_with_drain) warnings
- From the docs: "`.into_iter()` is simpler with better performance"

## Solution

- Replace `.drain(..)` for `Vec` with `.into_iter()`
  • Loading branch information
TimJentzsch authored and ItsDoot committed Feb 1, 2023
1 parent eb08bfb commit c2ce749
Show file tree
Hide file tree
Showing 8 changed files with 16 additions and 17 deletions.
4 changes: 2 additions & 2 deletions crates/bevy_asset/src/loader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,8 @@ impl<T: Asset> LoadedAsset<T> {

/// Adds dependencies on other assets at the provided paths.
#[must_use]
pub fn with_dependencies(mut self, mut asset_paths: Vec<AssetPath<'static>>) -> Self {
for asset_path in asset_paths.drain(..) {
pub fn with_dependencies(mut self, asset_paths: Vec<AssetPath<'static>>) -> Self {
for asset_path in asset_paths {
self.add_dependency(asset_path);
}
self
Expand Down
8 changes: 4 additions & 4 deletions crates/bevy_ecs/src/schedule/ambiguity_detection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -235,9 +235,9 @@ fn find_ambiguities(systems: &[SystemContainer]) -> Vec<(usize, usize, Vec<Compo
}
all_dependants[index] = dependants;
}
let mut all_relations = all_dependencies
.drain(..)
.zip(all_dependants.drain(..))
let all_relations = all_dependencies
.into_iter()
.zip(all_dependants.into_iter())
.enumerate()
.map(|(index, (dependencies, dependants))| {
let mut relations = FixedBitSet::with_capacity(systems.len());
Expand All @@ -250,7 +250,7 @@ fn find_ambiguities(systems: &[SystemContainer]) -> Vec<(usize, usize, Vec<Compo
let mut ambiguities = Vec::new();
let full_bitset: FixedBitSet = (0..systems.len()).collect();
let mut processed = FixedBitSet::with_capacity(systems.len());
for (index_a, relations) in all_relations.drain(..).enumerate() {
for (index_a, relations) in all_relations.into_iter().enumerate() {
// TODO: prove that `.take(index_a)` would be correct here, and uncomment it if so.
for index_b in full_bitset.difference(&relations)
// .take(index_a)
Expand Down
2 changes: 1 addition & 1 deletion crates/bevy_ecs/src/schedule/stage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ impl SystemStage {
}
}
});
for system in systems.drain(..) {
for system in systems {
self.add_system_inner(system, set_run_criteria_index);
}
self
Expand Down
4 changes: 2 additions & 2 deletions crates/bevy_ecs/src/system/system_param.rs
Original file line number Diff line number Diff line change
Expand Up @@ -203,12 +203,12 @@ fn assert_component_access_compatibility(
current: &FilteredAccess<ComponentId>,
world: &World,
) {
let mut conflicts = system_access.get_conflicts_single(current);
let conflicts = system_access.get_conflicts_single(current);
if conflicts.is_empty() {
return;
}
let conflicting_components = conflicts
.drain(..)
.into_iter()
.map(|component_id| world.components.get_info(component_id).unwrap().name())
.collect::<Vec<&str>>();
let accesses = conflicting_components.join(", ");
Expand Down
4 changes: 2 additions & 2 deletions crates/bevy_pbr/src/material.rs
Original file line number Diff line number Diff line change
Expand Up @@ -536,8 +536,8 @@ fn prepare_materials<M: Material>(
fallback_image: Res<FallbackImage>,
pipeline: Res<MaterialPipeline<M>>,
) {
let mut queued_assets = std::mem::take(&mut prepare_next_frame.assets);
for (handle, material) in queued_assets.drain(..) {
let queued_assets = std::mem::take(&mut prepare_next_frame.assets);
for (handle, material) in queued_assets.into_iter() {
match prepare_material(
&material,
&render_device,
Expand Down
4 changes: 2 additions & 2 deletions crates/bevy_render/src/render_asset.rs
Original file line number Diff line number Diff line change
Expand Up @@ -186,8 +186,8 @@ fn prepare_assets<R: RenderAsset>(
param: StaticSystemParam<<R as RenderAsset>::Param>,
) {
let mut param = param.into_inner();
let mut queued_assets = std::mem::take(&mut prepare_next_frame.assets);
for (handle, extracted_asset) in queued_assets.drain(..) {
let queued_assets = std::mem::take(&mut prepare_next_frame.assets);
for (handle, extracted_asset) in queued_assets {
match R::prepare_asset(extracted_asset, &mut param) {
Ok(prepared_asset) => {
render_assets.insert(handle, prepared_asset);
Expand Down
3 changes: 1 addition & 2 deletions crates/bevy_render/src/render_phase/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,7 @@ impl<I: BatchedPhaseItem> RenderPhase<I> {
/// Batches the compatible [`BatchedPhaseItem`]s of this render phase
pub fn batch(&mut self) {
// TODO: this could be done in-place
let mut items = std::mem::take(&mut self.items);
let mut items = items.drain(..);
let mut items = std::mem::take(&mut self.items).into_iter();

self.items.reserve(items.len());

Expand Down
4 changes: 2 additions & 2 deletions crates/bevy_sprite/src/mesh2d/material.rs
Original file line number Diff line number Diff line change
Expand Up @@ -471,8 +471,8 @@ fn prepare_materials_2d<M: Material2d>(
fallback_image: Res<FallbackImage>,
pipeline: Res<Material2dPipeline<M>>,
) {
let mut queued_assets = std::mem::take(&mut prepare_next_frame.assets);
for (handle, material) in queued_assets.drain(..) {
let queued_assets = std::mem::take(&mut prepare_next_frame.assets);
for (handle, material) in queued_assets {
match prepare_material2d(
&material,
&render_device,
Expand Down

0 comments on commit c2ce749

Please sign in to comment.