From 94e6fadb82a011644bd731313b12b2ed83ee02b9 Mon Sep 17 00:00:00 2001 From: Yagiz Nizipli Date: Sun, 25 Sep 2022 11:37:26 -0400 Subject: [PATCH] buffer: initialize TextDecoder once on blob for performance --- lib/internal/blob.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/lib/internal/blob.js b/lib/internal/blob.js index 8014a1bb5b0349..15309b8886c01c 100644 --- a/lib/internal/blob.js +++ b/lib/internal/blob.js @@ -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 @@ -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()); }