@@ -971,10 +971,7 @@ void IndexOfString(const FunctionCallbackInfo<Value>& args) {
971971 size_t result = haystack_length;
972972
973973 if (enc == UCS2 ) {
974- String::Value needle_value (isolate, needle);
975- if (*needle_value == nullptr )
976- return args.GetReturnValue ().Set (-1 );
977-
974+ TwoByteValue needle_value (isolate, needle);
978975 if (haystack_length < 2 || needle_value.length () < 1 ) {
979976 return args.GetReturnValue ().Set (-1 );
980977 }
@@ -995,27 +992,27 @@ void IndexOfString(const FunctionCallbackInfo<Value>& args) {
995992 offset / 2 ,
996993 is_forward);
997994 } else {
998- result =
999- nbytes::SearchString (reinterpret_cast <const uint16_t *>(haystack),
1000- haystack_length / 2 ,
1001- reinterpret_cast <const uint16_t *>(*needle_value),
1002- needle_value.length (),
1003- offset / 2 ,
1004- is_forward);
995+ result = nbytes::SearchString (reinterpret_cast <const uint16_t *>(haystack),
996+ haystack_length / 2 ,
997+ needle_value.out (),
998+ needle_value.length (),
999+ offset / 2 ,
1000+ is_forward);
10051001 }
10061002 result *= 2 ;
10071003 } else if (enc == UTF8 ) {
1008- String:: Utf8Value needle_value (isolate, needle);
1004+ Utf8Value needle_value (isolate, needle);
10091005 if (*needle_value == nullptr )
10101006 return args.GetReturnValue ().Set (-1 );
1011-
1012- result =
1013- nbytes::SearchString (reinterpret_cast <const uint8_t *>(haystack),
1014- haystack_length,
1015- reinterpret_cast <const uint8_t *>(*needle_value),
1016- needle_length,
1017- offset,
1018- is_forward);
1007+ CHECK_GE (needle_length, needle_value.length ());
1008+
1009+ result = nbytes::SearchString (
1010+ reinterpret_cast <const uint8_t *>(haystack),
1011+ haystack_length,
1012+ reinterpret_cast <const uint8_t *>(needle_value.out ()),
1013+ needle_length,
1014+ offset,
1015+ is_forward);
10191016 } else if (enc == LATIN1 ) {
10201017 uint8_t * needle_data = node::UncheckedMalloc<uint8_t >(needle_length);
10211018 if (needle_data == nullptr ) {
@@ -1261,10 +1258,10 @@ static void Btoa(const FunctionCallbackInfo<Value>& args) {
12611258 input->Length (),
12621259 buffer.out ());
12631260 } else {
1264- String::Value value (env->isolate (), input);
1261+ TwoByteValue value (env->isolate (), input);
12651262 MaybeStackBuffer<char > stack_buf (value.length ());
12661263 size_t out_len = simdutf::convert_utf16_to_latin1 (
1267- reinterpret_cast <const char16_t *>(* value),
1264+ reinterpret_cast <const char16_t *>(value. out () ),
12681265 value.length (),
12691266 stack_buf.out ());
12701267 if (out_len == 0 ) { // error
@@ -1318,8 +1315,8 @@ static void Atob(const FunctionCallbackInfo<Value>& args) {
13181315 buffer.SetLength (expected_length);
13191316 result = simdutf::base64_to_binary (data, input->Length (), buffer.out ());
13201317 } else { // 16-bit case
1321- String::Value value (env->isolate (), input);
1322- auto data = reinterpret_cast <const char16_t *>(* value);
1318+ TwoByteValue value (env->isolate (), input);
1319+ auto data = reinterpret_cast <const char16_t *>(value. out () );
13231320 size_t expected_length =
13241321 simdutf::maximal_binary_length_from_base64 (data, value.length ());
13251322 buffer.AllocateSufficientStorage (expected_length);
0 commit comments