GeezerVison is showing github.com — src: use non-deprecated WriteUtf8V2() method · nodejs/node@b81697d
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/crypto/crypto_util.cc +4-4Lines changed: 4 additions & 4 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -402,10 +402,10 @@ ByteSource ByteSource::FromString(Environment* env, Local<String> str, | 402 | 402 | size_t size = str->Utf8LengthV2(env->isolate()); | 403 | 403 | size_t alloc_size = ntc ? size + 1 : size; | 404 | 404 | auto out = DataPointer::Alloc(alloc_size); | 405 | | - int opts = String::NO_OPTIONS; | 406 | | - if (!ntc) opts |= String::NO_NULL_TERMINATION; | 407 | | - str->WriteUtf8( | 408 | | - env->isolate(), static_cast<char*>(out.get()), alloc_size, nullptr, opts); | | 405 | + int flags = String::WriteFlags::kNone; | | 406 | + if (ntc) flags |= String::WriteFlags::kNullTerminate; | | 407 | + str->WriteUtf8V2( | | 408 | + env->isolate(), static_cast<char*>(out.get()), alloc_size, flags); | 409 | 409 | return ByteSource::Allocated(out.release()); | 410 | 410 | } | 411 | 411 |
| |
Collapse file Copy file name to clipboardExpand all lines: src/encoding_binding.cc +11-12Lines changed: 11 additions & 12 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -101,13 +101,12 @@ void BindingData::EncodeInto(const FunctionCallbackInfo<Value>& args) { | 101 | 101 | char* write_result = static_cast<char*>(buf->Data()) + dest->ByteOffset(); | 102 | 102 | size_t dest_length = dest->ByteLength(); | 103 | 103 |
| 104 | | - int nchars; | 105 | | - int written = source->WriteUtf8( | 106 | | - isolate, | 107 | | - write_result, | 108 | | - dest_length, | 109 | | - &nchars, | 110 | | - String::NO_NULL_TERMINATION | String::REPLACE_INVALID_UTF8); | | 104 | + size_t nchars; | | 105 | + size_t written = source->WriteUtf8V2(isolate, | | 106 | + write_result, | | 107 | + dest_length, | | 108 | + String::WriteFlags::kReplaceInvalidUtf8, | | 109 | + &nchars); | 111 | 110 |
| 112 | 111 | binding_data->encode_into_results_buffer_[0] = nchars; | 113 | 112 | binding_data->encode_into_results_buffer_[1] = written; | @@ -131,11 +130,11 @@ void BindingData::EncodeUtf8String(const FunctionCallbackInfo<Value>& args) { | 131 | 130 |
| 132 | 131 | CHECK(bs); | 133 | 132 |
| 134 | | - str->WriteUtf8(isolate, | 135 | | - static_cast<char*>(bs->Data()), | 136 | | - -1, // We are certain that `data` is sufficiently large | 137 | | - nullptr, | 138 | | - String::NO_NULL_TERMINATION | String::REPLACE_INVALID_UTF8); | | 133 | + // We are certain that `data` is sufficiently large | | 134 | + str->WriteUtf8V2(isolate, | | 135 | + static_cast<char*>(bs->Data()), | | 136 | + bs->MaxByteLength(), | | 137 | + String::WriteFlags::kReplaceInvalidUtf8); | 139 | 138 |
| 140 | 139 | ab = ArrayBuffer::New(isolate, std::move(bs)); | 141 | 140 | } | |
Collapse file Copy file name to clipboardExpand all lines: src/js_native_api_v8.cc +6-6Lines changed: 6 additions & 6 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -2484,12 +2484,12 @@ napi_status NAPI_CDECL napi_get_value_string_utf8( | 2484 | 2484 | CHECK_ARG(env, result); | 2485 | 2485 | *result = val.As<v8::String>()->Utf8LengthV2(env->isolate); | 2486 | 2486 | } else if (bufsize != 0) { | 2487 | | - int copied = val.As<v8::String>()->WriteUtf8( | 2488 | | - env->isolate, | 2489 | | - buf, | 2490 | | - bufsize - 1, | 2491 | | - nullptr, | 2492 | | - v8::String::REPLACE_INVALID_UTF8 | v8::String::NO_NULL_TERMINATION); | | 2487 | + auto str = val.As<v8::String>(); | | 2488 | + size_t copied = | | 2489 | + str->WriteUtf8V2(env->isolate, | | 2490 | + buf, | | 2491 | + bufsize - 1, | | 2492 | + v8::String::WriteFlags::kReplaceInvalidUtf8); | 2493 | 2493 |
| 2494 | 2494 | buf[copied] = '\0'; | 2495 | 2495 | if (result != nullptr) { | |
Collapse file Copy file name to clipboardExpand all lines: src/string_bytes.cc +2-1Lines changed: 2 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -271,7 +271,8 @@ size_t StringBytes::Write(Isolate* isolate, | 271 | 271 |
| 272 | 272 | case BUFFER: | 273 | 273 | case UTF8: | 274 | | - nbytes = str->WriteUtf8(isolate, buf, buflen, nullptr, flags); | | 274 | + nbytes = str->WriteUtf8V2( | | 275 | + isolate, buf, buflen, String::WriteFlags::kReplaceInvalidUtf8); | 275 | 276 | break; | 276 | 277 |
| 277 | 278 | case UCS2: { | |
Collapse file Copy file name to clipboardExpand all lines: src/util.cc +2-6Lines changed: 2 additions & 6 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -125,12 +125,8 @@ static void MakeUtf8String(Isolate* isolate, | 125 | 125 | size_t storage = (3 * value_length) + 1; | 126 | 126 | target->AllocateSufficientStorage(storage); | 127 | 127 |
| 128 | | - // TODO(@anonrig): Use simdutf to speed up non-one-byte strings once it's | 129 | | - // implemented | 130 | | - const int flags = | 131 | | - String::NO_NULL_TERMINATION | String::REPLACE_INVALID_UTF8; | 132 | | - const int length = | 133 | | - string->WriteUtf8(isolate, target->out(), storage, nullptr, flags); | | 128 | + size_t length = string->WriteUtf8V2( | | 129 | + isolate, target->out(), storage, String::WriteFlags::kReplaceInvalidUtf8); | 134 | 130 | target->SetLengthAndZeroTerminate(length); | 135 | 131 | } | 136 | 132 |
| |
|