Skip to content

Commit

Permalink
Use subarray instead of slice to avoid unnecessary memory allocation
Browse files Browse the repository at this point in the history
  • Loading branch information
lambdalisue committed Jun 13, 2021
1 parent 14ed4ff commit 2dab9ae
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions reader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ export class WorkerReader implements Deno.Reader, Deno.Closer {

private readFromRemain(p: Uint8Array): number {
const n = p.byteLength;
const d = this.#remain.slice(0, n);
this.#remain = this.#remain.slice(n);
const d = this.#remain.subarray(0, n);
this.#remain = this.#remain.subarray(n);
p.set(d);
return d.byteLength;
}
Expand Down

0 comments on commit 2dab9ae

Please sign in to comment.