diff --git a/js/ringbuf.js b/js/ringbuf.js index 67171b8..851f9cb 100644 --- a/js/ringbuf.js +++ b/js/ringbuf.js @@ -344,6 +344,19 @@ export class RingBuffer { * @private */ _copy(input, offset_input, output, offset_output, size) { + if (!size) { + return; + } + // Fast-path: use `set(...)` if possible: copying all the input linearly to + // the output. + if ( + offset_input === 0 && + offset_output + input.length <= this._storage_capacity() && + input.length === size + ) { + output.set(input, offset_output); + return; + } for (let i = 0; i < size; i++) { output[offset_output + i] = input[offset_input + i]; } diff --git a/public/example/index.js b/public/example/index.js index 292397c..c34663a 100644 --- a/public/example/index.js +++ b/public/example/index.js @@ -596,6 +596,19 @@ class RingBuffer { * @private */ _copy(input, offset_input, output, offset_output, size) { + if (!size) { + return; + } + // Fast-path: use `set(...)` if possible: copying all the input linearly to + // the output. + if ( + offset_input === 0 && + offset_output + input.length <= this._storage_capacity() && + input.length === size + ) { + output.set(input, offset_output); + return; + } for (let i = 0; i < size; i++) { output[offset_output + i] = input[offset_input + i]; }
Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.
Alternative Proxies: