Skip to content

Commit

Permalink
buffer: initialize TextDecoder once on blob for performance
Browse files Browse the repository at this point in the history
  • Loading branch information
anonrig committed Sep 25, 2022
1 parent dc4398c commit 94e6fad
Showing 1 changed file with 1 addition and 2 deletions.
3 changes: 1 addition & 2 deletions lib/internal/blob.js
Expand Up @@ -78,6 +78,7 @@ let ReadableStream;
let URL;

const enc = new TextEncoder();
const dec = new TextDecoder();

// Yes, lazy loading is annoying but because of circular
// references between the url, internal/blob, and buffer
Expand Down Expand Up @@ -310,8 +311,6 @@ class Blob {
async text() {
if (!isBlob(this))
throw new ERR_INVALID_THIS('Blob');

const dec = new TextDecoder();
return dec.decode(await this.arrayBuffer());
}

Expand Down

0 comments on commit 94e6fad

Please sign in to comment.