Skip to content

Commit

Permalink
Do not create a new TextDecoder for every record
Browse files Browse the repository at this point in the history
  • Loading branch information
achim-k committed Dec 5, 2023
1 parent 009389d commit 4dea007
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions typescript/core/src/Reader.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { getBigUint64 } from "./getBigUint64";

const textDecoder = new TextDecoder();

export default class Reader {
#view: DataView;
offset: number;
#textDecoder = new TextDecoder();

constructor(view: DataView, offset = 0) {
this.#view = view;
Expand Down Expand Up @@ -39,7 +40,7 @@ export default class Reader {
if (this.offset + length > this.#view.byteLength) {
throw new Error(`String length ${length} exceeds bounds of buffer`);
}
const value = this.#textDecoder.decode(
const value = textDecoder.decode(
new Uint8Array(this.#view.buffer, this.#view.byteOffset + this.offset, length),
);
this.offset += length;
Expand Down

0 comments on commit 4dea007

Please sign in to comment.