GeezerVison is showing github.com — src: migrate `String::Value` to `String::ValueView` · nodejs/node@efa142c
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: src/inspector_js_api.cc +3-3Lines changed: 3 additions & 3 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -245,9 +245,9 @@ static void AsyncTaskScheduledWrapper(const FunctionCallbackInfo<Value>& args) { | 245 | 245 | Environment* env = Environment::GetCurrent(args); | 246 | 246 |
| 247 | 247 | CHECK(args[0]->IsString()); | 248 | | - Local<String> task_name = args[0].As<String>(); | 249 | | - String::Value task_name_value(args.GetIsolate(), task_name); | 250 | | - StringView task_name_view(*task_name_value, task_name_value.length()); | | 248 | + | | 249 | + TwoByteValue task_name_buffer(args.GetIsolate(), args[0]); | | 250 | + StringView task_name_view(*task_name_buffer, task_name_buffer.length()); | 251 | 251 |
| 252 | 252 | CHECK(args[1]->IsNumber()); | 253 | 253 | int64_t task_id = args[1]->IntegerValue(env->context()).FromJust(); | |
Collapse file Copy file name to clipboardExpand all lines: src/node_buffer.cc +12-15Lines changed: 12 additions & 15 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -965,11 +965,9 @@ void IndexOfString(const FunctionCallbackInfo<Value>& args) { | 965 | 965 | size_t result = haystack_length; | 966 | 966 |
| 967 | 967 | if (enc == UCS2) { | 968 | | - String::Value needle_value(isolate, needle); | 969 | | - if (*needle_value == nullptr) | 970 | | - return args.GetReturnValue().Set(-1); | | 968 | + TwoByteValue needle_buffer(isolate, needle); | 971 | 969 |
| 972 | | - if (haystack_length < 2 || needle_value.length() < 1) { | | 970 | + if (haystack_length < 2 || needle_buffer.length() < 1) { | 973 | 971 | return args.GetReturnValue().Set(-1); | 974 | 972 | } | 975 | 973 |
| @@ -989,13 +987,12 @@ void IndexOfString(const FunctionCallbackInfo<Value>& args) { | 989 | 987 | offset / 2, | 990 | 988 | is_forward); | 991 | 989 | } else { | 992 | | - result = | 993 | | - nbytes::SearchString(reinterpret_cast<const uint16_t*>(haystack), | 994 | | - haystack_length / 2, | 995 | | - reinterpret_cast<const uint16_t*>(*needle_value), | 996 | | - needle_value.length(), | 997 | | - offset / 2, | 998 | | - is_forward); | | 990 | + result = nbytes::SearchString(reinterpret_cast<const uint16_t*>(haystack), | | 991 | + haystack_length / 2, | | 992 | + needle_buffer.out(), | | 993 | + needle_buffer.length(), | | 994 | + offset / 2, | | 995 | + is_forward); | 999 | 996 | } | 1000 | 997 | result *= 2; | 1001 | 998 | } else if (enc == UTF8) { | @@ -1295,10 +1292,10 @@ static void Btoa(const FunctionCallbackInfo<Value>& args) { | 1295 | 1292 | input->Length(), | 1296 | 1293 | buffer.out()); | 1297 | 1294 | } else { | 1298 | | - String::Value value(env->isolate(), input); | | 1295 | + String::ValueView value(env->isolate(), input); | 1299 | 1296 | MaybeStackBuffer<char> stack_buf(value.length()); | 1300 | 1297 | size_t out_len = simdutf::convert_utf16_to_latin1( | 1301 | | - reinterpret_cast<const char16_t*>(*value), | | 1298 | + reinterpret_cast<const char16_t*>(value.data16()), | 1302 | 1299 | value.length(), | 1303 | 1300 | stack_buf.out()); | 1304 | 1301 | if (out_len == 0) { // error | @@ -1355,8 +1352,8 @@ static void Atob(const FunctionCallbackInfo<Value>& args) { | 1355 | 1352 | buffer.SetLength(expected_length); | 1356 | 1353 | result = simdutf::base64_to_binary(data, input->Length(), buffer.out()); | 1357 | 1354 | } else { // 16-bit case | 1358 | | - String::Value value(env->isolate(), input); | 1359 | | - auto data = reinterpret_cast<const char16_t*>(*value); | | 1355 | + String::ValueView value(env->isolate(), input); | | 1356 | + auto data = reinterpret_cast<const char16_t*>(value.data16()); | 1360 | 1357 | size_t expected_length = | 1361 | 1358 | simdutf::maximal_binary_length_from_base64(data, value.length()); | 1362 | 1359 | buffer.AllocateSufficientStorage(expected_length); | |
Collapse file Copy file name to clipboardExpand all lines: src/string_bytes.cc +10-10Lines changed: 10 additions & 10 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -305,11 +305,10 @@ size_t StringBytes::Write(Isolate* isolate, | 305 | 305 | input_view.length()); | 306 | 306 | } | 307 | 307 | } else { | 308 | | - String::Value value(isolate, str); | 309 | 308 | size_t written_len = buflen; | 310 | 309 | auto result = simdutf::base64_to_binary_safe( | 311 | | - reinterpret_cast<const char16_t*>(*value), | 312 | | - value.length(), | | 310 | + reinterpret_cast<const char16_t*>(input_view.data16()), | | 311 | + input_view.length(), | 313 | 312 | buf, | 314 | 313 | written_len, | 315 | 314 | simdutf::base64_url); | @@ -319,7 +318,8 @@ size_t StringBytes::Write(Isolate* isolate, | 319 | 318 | // The input does not follow the WHATWG forgiving-base64 specification | 320 | 319 | // (adapted for base64url with + and / replaced by - and _). | 321 | 320 | // https://infra.spec.whatwg.org/#forgiving-base64-decode | 322 | | - nbytes = nbytes::Base64Decode(buf, buflen, *value, value.length()); | | 321 | + nbytes = nbytes::Base64Decode( | | 322 | + buf, buflen, input_view.data16(), input_view.length()); | 323 | 323 | } | 324 | 324 | } | 325 | 325 | break; | @@ -344,19 +344,19 @@ size_t StringBytes::Write(Isolate* isolate, | 344 | 344 | input_view.length()); | 345 | 345 | } | 346 | 346 | } else { | 347 | | - String::Value value(isolate, str); | 348 | 347 | size_t written_len = buflen; | 349 | 348 | auto result = simdutf::base64_to_binary_safe( | 350 | | - reinterpret_cast<const char16_t*>(*value), | 351 | | - value.length(), | | 349 | + reinterpret_cast<const char16_t*>(input_view.data16()), | | 350 | + input_view.length(), | 352 | 351 | buf, | 353 | 352 | written_len); | 354 | 353 | if (result.error == simdutf::error_code::SUCCESS) { | 355 | 354 | nbytes = written_len; | 356 | 355 | } else { | 357 | 356 | // The input does not follow the WHATWG base64 specification | 358 | 357 | // https://infra.spec.whatwg.org/#forgiving-base64-decode | 359 | | - nbytes = nbytes::Base64Decode(buf, buflen, *value, value.length()); | | 358 | + nbytes = nbytes::Base64Decode( | | 359 | + buf, buflen, input_view.data16(), input_view.length()); | 360 | 360 | } | 361 | 361 | } | 362 | 362 | break; | @@ -369,8 +369,8 @@ size_t StringBytes::Write(Isolate* isolate, | 369 | 369 | reinterpret_cast<const char*>(input_view.data8()), | 370 | 370 | input_view.length()); | 371 | 371 | } else { | 372 | | - String::Value value(isolate, str); | 373 | | - nbytes = nbytes::HexDecode(buf, buflen, *value, value.length()); | | 372 | + String::ValueView value(isolate, str); | | 373 | + nbytes = nbytes::HexDecode(buf, buflen, value.data8(), value.length()); | 374 | 374 | } | 375 | 375 | break; | 376 | 376 |
| |
|