From d06a199c22c25dd628367c5445a36e74fcb6e13c Mon Sep 17 00:00:00 2001 From: Antoine du Hamel Date: Mon, 12 Dec 2022 16:17:53 +0100 Subject: [PATCH] lib: remove unnecessary lazy loading in `internal/encoding` PR-URL: https://github.com/nodejs/node/pull/45810 Reviewed-By: Daeyeon Jeong Reviewed-By: Yagiz Nizipli --- lib/internal/encoding.js | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/lib/internal/encoding.js b/lib/internal/encoding.js index 0e3c44d2e84fbb..5cf20ea04c98ff 100644 --- a/lib/internal/encoding.js +++ b/lib/internal/encoding.js @@ -56,12 +56,7 @@ const { decodeUTF8, } = internalBinding('buffer'); -let Buffer; -function lazyBuffer() { - if (Buffer === undefined) - Buffer = require('buffer').Buffer; - return Buffer; -} +const { Buffer } = require('buffer'); function validateEncoder(obj) { if (obj == null || obj[kEncoder] !== true) @@ -499,14 +494,14 @@ function makeTextDecoderJS() { validateDecoder(this); if (isAnyArrayBuffer(input)) { try { - input = lazyBuffer().from(input); + input = Buffer.from(input); } catch { input = empty; } } else if (isArrayBufferView(input)) { try { - input = lazyBuffer().from(input.buffer, input.byteOffset, - input.byteLength); + input = Buffer.from(input.buffer, input.byteOffset, + input.byteLength); } catch { input = empty; }