Skip to content

Commit

Permalink
lib: remove unnecessary lazy loading in internal/encoding
Browse files Browse the repository at this point in the history
PR-URL: #45810
Reviewed-By: Daeyeon Jeong <daeyeon.dev@gmail.com>
Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com>
  • Loading branch information
aduh95 authored and danielleadams committed Jan 4, 2023
1 parent c64692e commit 44cfe5e
Showing 1 changed file with 4 additions and 9 deletions.
13 changes: 4 additions & 9 deletions lib/internal/encoding.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,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)
Expand Down Expand Up @@ -517,14 +512,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;
}
Expand Down

0 comments on commit 44cfe5e

Please sign in to comment.