refactor: cleanup priority queue size handling
[poolifier.git] / src / priority-queue.ts
index 1c0d8c929967b2fa52f728f7b395ed013f044fda..e68fe37d16e732efc907562adbb9716b9793c612 100644 (file)
@@ -91,9 +91,7 @@ export class PriorityQueue<T> {
         --bucket
       }
     }
-    if (this.size > 0) {
-      --this.size
-    }
+    this.decrementSize()
     return this.nodeArray.shift()?.data
   }
 
@@ -160,4 +158,16 @@ export class PriorityQueue<T> {
     }
     return this.size
   }
+
+  /**
+   * Decrements the size of the priority queue.
+   *
+   * @returns The new size of the priority queue.
+   */
+  private decrementSize (): number {
+    if (this.size > 0) {
+      --this.size
+    }
+    return this.size
+  }
 }