Skip to content

Commit d7b5ec1

Browse files
committed
util: improve text-decoder performance
1 parent 79e26b5 commit d7b5ec1

File tree

2 files changed

+6
-13
lines changed

2 files changed

+6
-13
lines changed

lib/internal/encoding.js

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -411,15 +411,7 @@ function makeTextDecoderICU() {
411411

412412
decode(input = empty, options = kEmptyObject) {
413413
validateDecoder(this);
414-
if (isAnyArrayBuffer(input)) {
415-
try {
416-
input = lazyBuffer().from(input);
417-
} catch {
418-
// If the buffer is detached,
419-
// use an empty Uint8Array to avoid TypeError
420-
input = empty;
421-
}
422-
} else if (!isArrayBufferView(input)) {
414+
if (!isAnyArrayBuffer(input) && !isArrayBufferView(input)) {
423415
throw new ERR_INVALID_ARG_TYPE('input',
424416
['ArrayBuffer', 'ArrayBufferView'],
425417
input);

src/node_i18n.cc

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
#if defined(NODE_HAVE_I18N_SUPPORT)
4747

4848
#include "base_object-inl.h"
49+
#include "crypto/crypto_util.h"
4950
#include "node.h"
5051
#include "node_buffer.h"
5152
#include "node_errors.h"
@@ -440,7 +441,7 @@ void ConverterObject::Decode(const FunctionCallbackInfo<Value>& args) {
440441

441442
ConverterObject* converter;
442443
ASSIGN_OR_RETURN_UNWRAP(&converter, args[0].As<Object>());
443-
ArrayBufferViewContents<char> input(args[1]);
444+
crypto::ArrayBufferOrViewContents<char> input(args[1]);
444445
int flags = args[2]->Uint32Value(env->context()).ToChecked();
445446

446447
UErrorCode status = U_ZERO_ERROR;
@@ -454,9 +455,9 @@ void ConverterObject::Decode(const FunctionCallbackInfo<Value>& args) {
454455
// take up to 2 UChars to encode a character
455456
size_t limit = 2 * converter->min_char_size() *
456457
(!flush ?
457-
input.length() :
458+
input.size() :
458459
std::max(
459-
input.length(),
460+
input.size(),
460461
static_cast<size_t>(
461462
ucnv_toUCountPending(converter->conv(), &status))));
462463
status = U_ZERO_ERROR;
@@ -473,7 +474,7 @@ void ConverterObject::Decode(const FunctionCallbackInfo<Value>& args) {
473474
});
474475

475476
const char* source = input.data();
476-
size_t source_length = input.length();
477+
size_t source_length = input.size();
477478

478479
UChar* target = *result;
479480
ucnv_toUnicode(converter->conv(),

0 commit comments

Comments
 (0)