From e5b5df1261dd30dab2d2f55aeb253b2f751f5fb6 Mon Sep 17 00:00:00 2001 From: zero-systems <60021149+zero-systems@users.noreply.github.com> Date: Wed, 22 Jan 2020 07:35:22 +1000 Subject: [PATCH] Optimize vector fill in builder. (#89) * optimize vector fill --- actix-server/src/builder.rs | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/actix-server/src/builder.rs b/actix-server/src/builder.rs index df733759..0f3722c9 100644 --- a/actix-server/src/builder.rs +++ b/actix-server/src/builder.rs @@ -263,12 +263,14 @@ impl ServerBuilder { info!("Starting {} workers", self.threads); // start workers - let mut workers = Vec::new(); - for idx in 0..self.threads { - let worker = self.start_worker(idx, self.accept.get_notify()); - workers.push(worker.clone()); - self.workers.push((idx, worker)); - } + let workers = (0..self.threads) + .map(|idx| { + let worker = self.start_worker(idx, self.accept.get_notify()); + self.workers.push((idx, worker.clone())); + + worker + }) + .collect(); // start accept thread for sock in &self.sockets { @@ -380,7 +382,7 @@ impl ServerBuilder { .await; System::current().stop(); } - .boxed(), + .boxed(), ); } ready(())