@@ -986,11 +986,7 @@ void IndexOfString(const FunctionCallbackInfo<Value>& args) {
986986 size_t result = haystack_length;
987987
988988 if (enc == UCS2) {
989- String::Value needle_value (isolate, needle);
990- if (*needle_value == nullptr ) {
991- return args.GetReturnValue ().Set (-1 );
992- }
993-
989+ TwoByteValue needle_value (isolate, needle);
994990 if (haystack_length < 2 || needle_value.length () < 1 ) {
995991 return args.GetReturnValue ().Set (-1 );
996992 }
@@ -1011,27 +1007,27 @@ void IndexOfString(const FunctionCallbackInfo<Value>& args) {
10111007 offset / 2 ,
10121008 is_forward);
10131009 } else {
1014- result =
1015- nbytes::SearchString (reinterpret_cast <const uint16_t *>(haystack),
1016- haystack_length / 2 ,
1017- reinterpret_cast <const uint16_t *>(*needle_value),
1018- needle_value.length (),
1019- offset / 2 ,
1020- is_forward);
1010+ result = nbytes::SearchString (reinterpret_cast <const uint16_t *>(haystack),
1011+ haystack_length / 2 ,
1012+ needle_value.out (),
1013+ needle_value.length (),
1014+ offset / 2 ,
1015+ is_forward);
10211016 }
10221017 result *= 2 ;
10231018 } else if (enc == UTF8) {
1024- String:: Utf8Value needle_value (isolate, needle);
1019+ Utf8Value needle_value (isolate, needle);
10251020 if (*needle_value == nullptr )
10261021 return args.GetReturnValue ().Set (-1 );
1027-
1028- result =
1029- nbytes::SearchString (reinterpret_cast <const uint8_t *>(haystack),
1030- haystack_length,
1031- reinterpret_cast <const uint8_t *>(*needle_value),
1032- needle_length,
1033- offset,
1034- is_forward);
1022+ CHECK_GE (needle_length, needle_value.length ());
1023+
1024+ result = nbytes::SearchString (
1025+ reinterpret_cast <const uint8_t *>(haystack),
1026+ haystack_length,
1027+ reinterpret_cast <const uint8_t *>(needle_value.out ()),
1028+ needle_length,
1029+ offset,
1030+ is_forward);
10351031 } else if (enc == LATIN1) {
10361032 uint8_t * needle_data = node::UncheckedMalloc<uint8_t >(needle_length);
10371033 if (needle_data == nullptr ) {
@@ -1316,10 +1312,10 @@ static void Btoa(const FunctionCallbackInfo<Value>& args) {
13161312 input->Length (),
13171313 buffer.out ());
13181314 } else {
1319- String::Value value (env->isolate (), input);
1315+ TwoByteValue value (env->isolate (), input);
13201316 MaybeStackBuffer<char > stack_buf (value.length ());
13211317 size_t out_len = simdutf::convert_utf16_to_latin1 (
1322- reinterpret_cast <const char16_t *>(* value),
1318+ reinterpret_cast <const char16_t *>(value. out () ),
13231319 value.length (),
13241320 stack_buf.out ());
13251321 if (out_len == 0 ) { // error
@@ -1370,8 +1366,8 @@ static void Atob(const FunctionCallbackInfo<Value>& args) {
13701366 buffer.SetLength (expected_length);
13711367 result = simdutf::base64_to_binary (data, input->Length (), buffer.out ());
13721368 } else { // 16-bit case
1373- String::Value value (env->isolate (), input);
1374- auto data = reinterpret_cast <const char16_t *>(* value);
1369+ TwoByteValue value (env->isolate (), input);
1370+ auto data = reinterpret_cast <const char16_t *>(value. out () );
13751371 size_t expected_length =
13761372 simdutf::maximal_binary_length_from_base64 (data, value.length ());
13771373 buffer.AllocateSufficientStorage (expected_length);
0 commit comments