From: Jérôme Benoit Date: Mon, 3 Apr 2023 10:04:06 +0000 (+0200) Subject: perf: remove unneeded nullish check in hot code paths X-Git-Tag: v2.4.0-0~7 X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=867d34f8cfc5f4a8fbaa4eb27520c8b9469cc80e;p=poolifier.git perf: remove unneeded nullish check in hot code paths Signed-off-by: Jérôme Benoit --- diff --git a/src/pools/selection-strategies/round-robin-worker-choice-strategy.ts b/src/pools/selection-strategies/round-robin-worker-choice-strategy.ts index a2327587..9bf49a3c 100644 --- a/src/pools/selection-strategies/round-robin-worker-choice-strategy.ts +++ b/src/pools/selection-strategies/round-robin-worker-choice-strategy.ts @@ -26,7 +26,7 @@ export class RoundRobinWorkerChoiceStrategy< /** {@inheritDoc} */ public choose (): Worker { - const chosenWorker = this.pool.workers[this.nextWorkerId]?.worker + const chosenWorker = this.pool.workers[this.nextWorkerId].worker this.nextWorkerId = this.nextWorkerId === this.pool.workers.length - 1 ? 0 diff --git a/src/pools/selection-strategies/weighted-round-robin-worker-choice-strategy.ts b/src/pools/selection-strategies/weighted-round-robin-worker-choice-strategy.ts index 9ee4fa65..5c5e6474 100644 --- a/src/pools/selection-strategies/weighted-round-robin-worker-choice-strategy.ts +++ b/src/pools/selection-strategies/weighted-round-robin-worker-choice-strategy.ts @@ -67,7 +67,7 @@ export class WeightedRoundRobinWorkerChoiceStrategy< /** {@inheritDoc} */ public choose (): Worker { - const chosenWorker = this.pool.workers[this.currentWorkerId]?.worker + const chosenWorker = this.pool.workers[this.currentWorkerId].worker if (this.isDynamicPool && !this.workersTaskRunTime.has(chosenWorker)) { this.initWorkerTaskRunTime(chosenWorker) } @@ -89,7 +89,7 @@ export class WeightedRoundRobinWorkerChoiceStrategy< ? 0 : this.currentWorkerId + 1 this.setWorkerTaskRunTime( - this.pool.workers[this.currentWorkerId]?.worker, + this.pool.workers[this.currentWorkerId].worker, workerTaskWeight, 0 )