diff options
author | Anna Henningsen <anna@addaleax.net> | 2019-05-26 23:34:51 +0300 |
---|---|---|
committer | Anna Henningsen <anna@addaleax.net> | 2019-05-29 20:28:38 +0300 |
commit | 5026db142ab5d07c7144dfb272512d3388476a77 (patch) | |
tree | bfe8ca1908b0b94aae498b33ecd3174c7033b2f4 /src/node_i18n.cc | |
parent | 7329c8fe52eb36a238dfdcdd83b8f81034d983fa (diff) |
src: use ArrayBufferViewContents more frequently
Using `ArrayBufferViewContents` over
`Buffer::Data()`/`Buffer::Length()` or `SPREAD_BUFFER_ARG` has the
advantages of creating fewer individual variables to keep track off,
not being a “magic” macro that creates variables, reducing code size,
and being faster when receiving on-heap TypedArrays.
PR-URL: https://github.com/nodejs/node/pull/27920
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Sam Roberts <vieuxtech@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Diffstat (limited to 'src/node_i18n.cc')
-rw-r--r-- | src/node_i18n.cc | 14 |
1 files changed, 6 insertions, 8 deletions
diff --git a/src/node_i18n.cc b/src/node_i18n.cc index 8ccda35056c..ad5c8283924 100644 --- a/src/node_i18n.cc +++ b/src/node_i18n.cc @@ -205,14 +205,13 @@ class ConverterObject : public BaseObject, Converter { ConverterObject* converter; ASSIGN_OR_RETURN_UNWRAP(&converter, args[0].As<Object>()); - SPREAD_BUFFER_ARG(args[1], input_obj); + ArrayBufferViewContents<char> input(args[1]); int flags = args[2]->Uint32Value(env->context()).ToChecked(); UErrorCode status = U_ZERO_ERROR; MaybeStackBuffer<UChar> result; MaybeLocal<Object> ret; - size_t limit = ucnv_getMinCharSize(converter->conv) * - input_obj_length; + size_t limit = ucnv_getMinCharSize(converter->conv) * input.length(); if (limit > 0) result.AllocateSufficientStorage(limit); @@ -225,8 +224,8 @@ class ConverterObject : public BaseObject, Converter { } }); - const char* source = input_obj_data; - size_t source_length = input_obj_length; + const char* source = input.data(); + size_t source_length = input.length(); if (converter->unicode_ && !converter->ignoreBOM_ && !converter->bomSeen_) { int32_t bomOffset = 0; @@ -455,8 +454,7 @@ void Transcode(const FunctionCallbackInfo<Value>&args) { UErrorCode status = U_ZERO_ERROR; MaybeLocal<Object> result; - CHECK(Buffer::HasInstance(args[0])); - SPREAD_BUFFER_ARG(args[0], ts_obj); + ArrayBufferViewContents<char> input(args[0]); const enum encoding fromEncoding = ParseEncoding(isolate, args[1], BUFFER); const enum encoding toEncoding = ParseEncoding(isolate, args[2], BUFFER); @@ -490,7 +488,7 @@ void Transcode(const FunctionCallbackInfo<Value>&args) { } result = tfn(env, EncodingName(fromEncoding), EncodingName(toEncoding), - ts_obj_data, ts_obj_length, &status); + input.data(), input.length(), &status); } else { status = U_ILLEGAL_ARGUMENT_ERROR; } |