From: Jérôme Benoit Date: Sat, 11 May 2024 17:35:01 +0000 (+0200) Subject: refactor: cleanup priority queue size handling X-Git-Tag: v4.0.7~9 X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=65729b19f8371b8034d61c7771c8ece6e3692260;p=poolifier.git refactor: cleanup priority queue size handling Signed-off-by: Jérôme Benoit --- diff --git a/.eslintrc.cjs b/.eslintrc.cjs index ef9e86c0..af3c350b 100644 --- a/.eslintrc.cjs +++ b/.eslintrc.cjs @@ -45,6 +45,7 @@ module.exports = defineConfig({ 'cpus', 'cryptographically', 'ctx', + 'decrement', 'deprecations', 'deque', 'dequeue', diff --git a/src/priority-queue.ts b/src/priority-queue.ts index 1c0d8c92..e68fe37d 100644 --- a/src/priority-queue.ts +++ b/src/priority-queue.ts @@ -91,9 +91,7 @@ export class PriorityQueue { --bucket } } - if (this.size > 0) { - --this.size - } + this.decrementSize() return this.nodeArray.shift()?.data } @@ -160,4 +158,16 @@ export class PriorityQueue { } 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 + } }