From 589ceb6d38676fc486dba20d32b6ca35360ac653 Mon Sep 17 00:00:00 2001 From: Christof Petig Date: Wed, 1 Jun 2022 22:47:53 +0200 Subject: [PATCH] avoid one allocation, spotted by imbris --- voxygen/src/scene/particle.rs | 28 ++++++++++++---------------- 1 file changed, 12 insertions(+), 16 deletions(-) diff --git a/voxygen/src/scene/particle.rs b/voxygen/src/scene/particle.rs index aafb60ade3..a1d11645d7 100644 --- a/voxygen/src/scene/particle.rs +++ b/voxygen/src/scene/particle.rs @@ -1314,22 +1314,18 @@ impl ParticleMgr { |smoker| smoker.strength, ); if let Ok(chosen) = chosen { - let mut smoke_particles: Vec = chosen - .map(|smoker| { - Particle::new( - Duration::from_secs_f32(lifetime), - time, - if rng.gen::() > smoker.dry_chance { - ParticleMode::BlackSmoke - } else { - ParticleMode::CampfireSmoke - }, - smoker.position.map(|e: i32| e as f32 + rng.gen::()), - ) - }) - .collect(); - - self.particles.append(&mut smoke_particles); + self.particles.extend(chosen.map(|smoker| { + Particle::new( + Duration::from_secs_f32(lifetime), + time, + if rng.gen::() > smoker.dry_chance { + ParticleMode::BlackSmoke + } else { + ParticleMode::CampfireSmoke + }, + smoker.position.map(|e: i32| e as f32 + rng.gen::()), + ) + })); } }); }