GeezerVison is showing github.com — util: improve text decoder performance · nodejs/node@cd740d0
File treeExpand file treeCollapse file tree Open diff view settings Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: lib/internal/encoding.js +1-11Lines changed: 1 addition & 11 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -18,7 +18,6 @@ const { | 18 | 18 | } = primordials; | 19 | 19 |
| 20 | 20 | const { | 21 | | - ERR_ENCODING_INVALID_ENCODED_DATA, | 22 | 21 | ERR_ENCODING_NOT_SUPPORTED, | 23 | 22 | ERR_INVALID_ARG_TYPE, | 24 | 23 | ERR_INVALID_THIS, | @@ -411,11 +410,6 @@ function makeTextDecoderICU() { | 411 | 410 |
| 412 | 411 | decode(input = empty, options = kEmptyObject) { | 413 | 412 | validateDecoder(this); | 414 | | - if (!isAnyArrayBuffer(input) && !isArrayBufferView(input)) { | 415 | | - throw new ERR_INVALID_ARG_TYPE('input', | 416 | | - ['ArrayBuffer', 'ArrayBufferView'], | 417 | | - input); | 418 | | - } | 419 | 413 | validateObject(options, 'options', { | 420 | 414 | nullable: true, | 421 | 415 | allowArray: true, | @@ -426,11 +420,7 @@ function makeTextDecoderICU() { | 426 | 420 | if (options !== null) | 427 | 421 | flags |= options.stream ? 0 : CONVERTER_FLAGS_FLUSH; | 428 | 422 |
| 429 | | - const ret = _decode(this[kHandle], input, flags); | 430 | | - if (typeof ret === 'number') { | 431 | | - throw new ERR_ENCODING_INVALID_ENCODED_DATA(this.encoding, ret); | 432 | | - } | 433 | | - return ret; | | 423 | + return _decode(this[kHandle], input, flags, this.encoding); | 434 | 424 | } | 435 | 425 | } | 436 | 426 |
| |
Collapse file Copy file name to clipboardExpand all lines: src/node_errors.h +1Lines changed: 1 addition & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -60,6 +60,7 @@ void OOMErrorHandler(const char* location, bool is_heap_oom); | 60 | 60 | V(ERR_CRYPTO_JOB_INIT_FAILED, Error) \ | 61 | 61 | V(ERR_DLOPEN_DISABLED, Error) \ | 62 | 62 | V(ERR_DLOPEN_FAILED, Error) \ | | 63 | + V(ERR_ENCODING_INVALID_ENCODED_DATA, TypeError) \ | 63 | 64 | V(ERR_EXECUTION_ENVIRONMENT_NOT_AVAILABLE, Error) \ | 64 | 65 | V(ERR_INVALID_ADDRESS, Error) \ | 65 | 66 | V(ERR_INVALID_ARG_VALUE, TypeError) \ | |
Collapse file Copy file name to clipboardExpand all lines: src/node_i18n.cc +18-6Lines changed: 18 additions & 6 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -436,13 +436,25 @@ void ConverterObject::Create(const FunctionCallbackInfo<Value>& args) { | 436 | 436 | void ConverterObject::Decode(const FunctionCallbackInfo<Value>& args) { | 437 | 437 | Environment* env = Environment::GetCurrent(args); | 438 | 438 |
| 439 | | - CHECK_GE(args.Length(), 3); // Converter, Buffer, Flags | | 439 | + CHECK_GE(args.Length(), 4); // Converter, Buffer, Flags, Encoding | 440 | 440 |
| 441 | 441 | ConverterObject* converter; | 442 | 442 | ASSIGN_OR_RETURN_UNWRAP(&converter, args[0].As<Object>()); | | 443 | + | | 444 | + if (!(args[1]->IsArrayBuffer() || args[1]->IsSharedArrayBuffer() || | | 445 | + args[1]->IsArrayBufferView())) { | | 446 | + return node::THROW_ERR_INVALID_ARG_TYPE( | | 447 | + env->isolate(), | | 448 | + "The \"input\" argument must be an instance of SharedArrayBuffer, " | | 449 | + "ArrayBuffer or ArrayBufferView."); | | 450 | + } | | 451 | + | 443 | 452 | ArrayBufferViewContents<char> input(args[1]); | 444 | 453 | int flags = args[2]->Uint32Value(env->context()).ToChecked(); | 445 | 454 |
| | 455 | + CHECK(args[3]->IsString()); | | 456 | + Local<String> from_encoding = args[3].As<String>(); | | 457 | + | 446 | 458 | UErrorCode status = U_ZERO_ERROR; | 447 | 459 | MaybeStackBuffer<UChar> result; | 448 | 460 |
| @@ -524,14 +536,14 @@ void ConverterObject::Decode(const FunctionCallbackInfo<Value>& args) { | 524 | 536 | Local<Value> ret; | 525 | 537 | if (encoded.ToLocal(&ret)) { | 526 | 538 | args.GetReturnValue().Set(ret); | 527 | | - } else { | 528 | | - args.GetReturnValue().Set(error); | | 539 | + return; | 529 | 540 | } | 530 | | - | 531 | | - return; | 532 | 541 | } | 533 | 542 |
| 534 | | - args.GetReturnValue().Set(status); | | 543 | + node::THROW_ERR_ENCODING_INVALID_ENCODED_DATA( | | 544 | + env->isolate(), | | 545 | + "The encoded data was not valid for encoding %s", | | 546 | + *node::Utf8Value(env->isolate(), from_encoding)); | 535 | 547 | } | 536 | 548 |
| 537 | 549 | ConverterObject::ConverterObject( | |
|