Skip to content

Commit 2c692dc

Browse files
perf: remove need for additional vec
1 parent e9c9d49 commit 2c692dc

File tree

1 file changed

+7
-10
lines changed

1 file changed

+7
-10
lines changed

frameworks/Rust/axum/src/pg/database.rs

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -90,21 +90,18 @@ impl PgConnection {
9090
}
9191

9292
pub async fn update_worlds(&self, num: usize) -> Result<Vec<World>, PgError> {
93-
let worlds = self.fetch_random_worlds(num).await?;
93+
let mut worlds = self.fetch_random_worlds(num).await?;
9494

9595
// Update the worlds with new random numbers
9696
let mut rng = SmallRng::from_rng(&mut thread_rng()).unwrap();
9797
let mut ids = Vec::with_capacity(num);
9898
let mut nids = Vec::with_capacity(num);
99-
let worlds: Vec<World> = worlds
100-
.into_iter()
101-
.map(|mut w| {
102-
w.randomnumber = random_id(&mut rng);
103-
ids.push(w.id);
104-
nids.push(w.randomnumber);
105-
w
106-
})
107-
.collect();
99+
100+
for w in &mut worlds {
101+
w.randomnumber = random_id(&mut rng);
102+
ids.push(w.id);
103+
nids.push(w.randomnumber);
104+
}
108105

109106
// Update the random worlds in the database.
110107
self.client

0 commit comments

Comments
 (0)