X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=src%2Fcircular-buffer.ts;h=7d12069fe369b48c72bf592d9b46a8eae0294031;hb=fcfc3353eb4053c02f64c80a14ae142d44388a71;hp=a56cd09d551e67cc865ac4e40950cb6988b76362;hpb=0cd1f28c613a876bfedd3b70b987e37f91888ed0;p=poolifier.git diff --git a/src/circular-buffer.ts b/src/circular-buffer.ts index a56cd09d..7d12069f 100644 --- a/src/circular-buffer.ts +++ b/src/circular-buffer.ts @@ -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) {