lib: remove unnecessary lazy loading in internal/encoding

PR-URL: https://github.com/nodejs/node/pull/45810
Reviewed-By: Daeyeon Jeong <daeyeon.dev@gmail.com>
Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com>
This commit is contained in:
Antoine du Hamel 2022-12-12 16:17:53 +01:00 committed by GitHub
parent bb908fc886
commit aa2ca81f60
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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;
}