diff options
author | Marcos Casagrande <marcoscvp90@gmail.com> | 2020-04-30 22:39:25 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-04-30 16:39:25 -0400 |
commit | 9ded17d722b8da124987cdf16976589a46f2d3f5 (patch) | |
tree | 4b7689c9097cb2081155d9ca65165fe1b5e4829c | |
parent | 4297b865f97d3087fa80a5a73d424d2ea183c6d8 (diff) |
BREAKING: reorder std/io/utils copyBytes arguments (#5022)
-rw-r--r-- | std/bytes/mod.ts | 4 | ||||
-rw-r--r-- | std/io/bufio.ts | 10 | ||||
-rw-r--r-- | std/io/bufio_test.ts | 2 | ||||
-rw-r--r-- | std/io/util.ts | 4 | ||||
-rw-r--r-- | std/io/util_test.ts | 10 | ||||
-rw-r--r-- | std/ws/mod.ts | 4 |
6 files changed, 17 insertions, 17 deletions
diff --git a/std/bytes/mod.ts b/std/bytes/mod.ts index 88eb97710..7d51e995c 100644 --- a/std/bytes/mod.ts +++ b/std/bytes/mod.ts @@ -86,10 +86,10 @@ export function repeat(b: Uint8Array, count: number): Uint8Array { const nb = new Uint8Array(b.length * count); - let bp = copyBytes(nb, b); + let bp = copyBytes(b, nb); for (; bp < nb.length; bp *= 2) { - copyBytes(nb, nb.slice(0, bp), bp); + copyBytes(nb.slice(0, bp), nb, bp); } return nb; diff --git a/std/io/bufio.ts b/std/io/bufio.ts index 9a22c7f3e..aa74809fe 100644 --- a/std/io/bufio.ts +++ b/std/io/bufio.ts @@ -149,7 +149,7 @@ export class BufReader implements Reader { } // copy as much as we can - const copied = copyBytes(p, this.buf.subarray(this.r, this.w), 0); + const copied = copyBytes(this.buf.subarray(this.r, this.w), p, 0); this.r += copied; // this.lastByte = this.buf[this.r - 1]; // this.lastCharSize = -1; @@ -509,7 +509,7 @@ export class BufWriter extends AbstractBufBase implements Writer { throw e; } } else { - numBytesWritten = copyBytes(this.buf, data, this.usedBufferBytes); + numBytesWritten = copyBytes(data, this.buf, this.usedBufferBytes); this.usedBufferBytes += numBytesWritten; await this.flush(); } @@ -517,7 +517,7 @@ export class BufWriter extends AbstractBufBase implements Writer { data = data.subarray(numBytesWritten); } - numBytesWritten = copyBytes(this.buf, data, this.usedBufferBytes); + numBytesWritten = copyBytes(data, this.buf, this.usedBufferBytes); this.usedBufferBytes += numBytesWritten; totalBytesWritten += numBytesWritten; return totalBytesWritten; @@ -603,7 +603,7 @@ export class BufWriterSync extends AbstractBufBase implements WriterSync { throw e; } } else { - numBytesWritten = copyBytes(this.buf, data, this.usedBufferBytes); + numBytesWritten = copyBytes(data, this.buf, this.usedBufferBytes); this.usedBufferBytes += numBytesWritten; this.flush(); } @@ -611,7 +611,7 @@ export class BufWriterSync extends AbstractBufBase implements WriterSync { data = data.subarray(numBytesWritten); } - numBytesWritten = copyBytes(this.buf, data, this.usedBufferBytes); + numBytesWritten = copyBytes(data, this.buf, this.usedBufferBytes); this.usedBufferBytes += numBytesWritten; totalBytesWritten += numBytesWritten; return totalBytesWritten; diff --git a/std/io/bufio_test.ts b/std/io/bufio_test.ts index a4f03338d..17cc873fd 100644 --- a/std/io/bufio_test.ts +++ b/std/io/bufio_test.ts @@ -201,7 +201,7 @@ class TestReader implements Reader { if (nread === 0) { return Promise.resolve(null); } - copyBytes(buf as Uint8Array, this.data); + copyBytes(this.data, buf as Uint8Array); this.data = this.data.subarray(nread); return Promise.resolve(nread); } diff --git a/std/io/util.ts b/std/io/util.ts index 18ddb4def..237747a89 100644 --- a/std/io/util.ts +++ b/std/io/util.ts @@ -9,12 +9,12 @@ import { encode } from "../encoding/utf8.ts"; * Copy bytes from one Uint8Array to another. Bytes from `src` which don't fit * into `dst` will not be copied. * - * @param dst Destination byte array * @param src Source byte array + * @param dst Destination byte array * @param off Offset into `dst` at which to begin writing values from `src`. * @return number of bytes copied */ -export function copyBytes(dst: Uint8Array, src: Uint8Array, off = 0): number { +export function copyBytes(src: Uint8Array, dst: Uint8Array, off = 0): number { off = Math.max(0, Math.min(off, dst.byteLength)); const dstBytesAvailable = dst.byteLength - off; if (src.byteLength > dstBytesAvailable) { diff --git a/std/io/util_test.ts b/std/io/util_test.ts index 17f11b945..68a398bd1 100644 --- a/std/io/util_test.ts +++ b/std/io/util_test.ts @@ -9,31 +9,31 @@ test("[io/tuil] copyBytes", function (): void { dst.fill(0); let src = Uint8Array.of(1, 2); - let len = copyBytes(dst, src, 0); + let len = copyBytes(src, dst, 0); assert(len === 2); assertEquals(dst, Uint8Array.of(1, 2, 0, 0)); dst.fill(0); src = Uint8Array.of(1, 2); - len = copyBytes(dst, src, 1); + len = copyBytes(src, dst, 1); assert(len === 2); assertEquals(dst, Uint8Array.of(0, 1, 2, 0)); dst.fill(0); src = Uint8Array.of(1, 2, 3, 4, 5); - len = copyBytes(dst, src); + len = copyBytes(src, dst); assert(len === 4); assertEquals(dst, Uint8Array.of(1, 2, 3, 4)); dst.fill(0); src = Uint8Array.of(1, 2); - len = copyBytes(dst, src, 100); + len = copyBytes(src, dst, 100); assert(len === 0); assertEquals(dst, Uint8Array.of(0, 0, 0, 0)); dst.fill(0); src = Uint8Array.of(3, 4); - len = copyBytes(dst, src, -2); + len = copyBytes(src, dst, -2); assert(len === 2); assertEquals(dst, Uint8Array.of(3, 4, 0, 0)); }); diff --git a/std/ws/mod.ts b/std/ws/mod.ts index 2a18cded7..569936706 100644 --- a/std/ws/mod.ts +++ b/std/ws/mod.ts @@ -338,11 +338,11 @@ class WebSocketImpl implements WebSocket { async read(p: Uint8Array): Promise<number | null> { for await (const ev of this.receive()) { if (ev instanceof Uint8Array) { - return copyBytes(p, ev); + return copyBytes(ev, p); } if (typeof ev === "string") { - return copyBytes(p, encode(ev)); + return copyBytes(encode(ev), p); } } |