diff options
author | Marcos Casagrande <marcoscvp90@gmail.com> | 2020-04-30 21:46:44 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-04-30 15:46:44 -0400 |
commit | 4297b865f97d3087fa80a5a73d424d2ea183c6d8 (patch) | |
tree | 4dd860f4bebccf1c8a1d3c8edcc7ff7371895180 /cli/js | |
parent | 3e72d63205662f3ff38d561cb1bebd8ffe54e3f2 (diff) |
internal: reorder Buffer's copyBytes arguments (#5021)
Diffstat (limited to 'cli/js')
-rw-r--r-- | cli/js/buffer.ts | 10 |
1 files changed, 5 insertions, 5 deletions
diff --git a/cli/js/buffer.ts b/cli/js/buffer.ts index dbe7606fd..8389db4f9 100644 --- a/cli/js/buffer.ts +++ b/cli/js/buffer.ts @@ -17,7 +17,7 @@ const MAX_SIZE = 2 ** 32 - 2; // `off` is the offset into `dst` where it will at which to begin writing values // from `src`. // Returns the number of bytes copied. -function copyBytes(dst: Uint8Array, src: Uint8Array, off = 0): number { +function copyBytes(src: Uint8Array, dst: Uint8Array, off = 0): number { const r = dst.byteLength - off; if (src.byteLength > r) { src = src.subarray(0, r); @@ -95,7 +95,7 @@ export class Buffer implements Reader, ReaderSync, Writer, WriterSync { } return null; } - const nread = copyBytes(p, this.#buf.subarray(this.#off)); + const nread = copyBytes(this.#buf.subarray(this.#off), p); this.#off += nread; return nread; } @@ -107,7 +107,7 @@ export class Buffer implements Reader, ReaderSync, Writer, WriterSync { writeSync(p: Uint8Array): number { const m = this.#grow(p.byteLength); - return copyBytes(this.#buf, p, m); + return copyBytes(p, this.#buf, m); } write(p: Uint8Array): Promise<number> { @@ -132,13 +132,13 @@ export class Buffer implements Reader, ReaderSync, Writer, WriterSync { // ArrayBuffer. We only need m+n <= c to slide, but // we instead let capacity get twice as large so we // don't spend all our time copying. - copyBytes(this.#buf, this.#buf.subarray(this.#off)); + copyBytes(this.#buf.subarray(this.#off), this.#buf); } else if (c > MAX_SIZE - c - n) { throw new Error("The buffer cannot be grown beyond the maximum size."); } else { // Not enough space anywhere, we need to allocate. const buf = new Uint8Array(2 * c + n); - copyBytes(buf, this.#buf.subarray(this.#off)); + copyBytes(this.#buf.subarray(this.#off), buf); this.#buf = buf; } // Restore this.#off and len(this.#buf). |