perf: remove unneeded nullish check in hot code paths
authorJérôme Benoit <jerome.benoit@sap.com>
Mon, 3 Apr 2023 10:04:06 +0000 (12:04 +0200)
committerJérôme Benoit <jerome.benoit@sap.com>
Mon, 3 Apr 2023 10:04:06 +0000 (12:04 +0200)
Signed-off-by: Jérôme Benoit <jerome.benoit@sap.com>
src/pools/selection-strategies/round-robin-worker-choice-strategy.ts
src/pools/selection-strategies/weighted-round-robin-worker-choice-strategy.ts

index a23275873909b0731cb3d514af74f0b9fb59090a..9bf49a3c3597bef69d5c4ef5b0408ccfccc5206a 100644 (file)
@@ -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
index 9ee4fa656632c7fcdfc982e5b7cf40b794d57e97..5c5e6474eb3c88bf2838bca9be65add4081194ef 100644 (file)
@@ -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
       )