perf: enable prioritized tasks queue only when necessary
[poolifier.git] / src / circular-buffer.ts
index a56cd09d551e67cc865ac4e40950cb6988b76362..7d12069fe369b48c72bf592d9b46a8eae0294031 100644 (file)
@@ -11,7 +11,7 @@ export const defaultBufferSize = 2048
 export class CircularBuffer {
   private readIdx: number
   private writeIdx: number
-  private items: Float32Array
+  private readonly items: Float32Array
   private readonly maxArrayIdx: number
   public size: number
 
@@ -65,14 +65,14 @@ export class CircularBuffer {
    * @returns Number from buffer.
    */
   public get (): number | undefined {
-    const data = this.items[this.readIdx]
-    if (data === -1) {
+    const number = this.items[this.readIdx]
+    if (number === -1) {
       return
     }
     this.items[this.readIdx] = -1
     this.readIdx = this.readIdx === this.maxArrayIdx ? 0 : this.readIdx + 1
     --this.size
-    return data
+    return number
   }
 
   /**
@@ -84,10 +84,15 @@ export class CircularBuffer {
     return Array.from(this.items.filter(item => item !== -1))
   }
 
+  /**
+   * Checks the buffer size.
+   *
+   * @param size - Buffer size.
+   */
   private checkSize (size: number): void {
     if (!Number.isSafeInteger(size)) {
       throw new TypeError(
-        `Invalid circular buffer size: ${size} is not an integer`
+        `Invalid circular buffer size: '${size}' is not an integer`
       )
     }
     if (size < 0) {