deps: V8: cherry-pick 64b36b441179

Original commit message:

    optimize ascii fast path in WriteUtf8V2

    Change-Id: If28168cb4395b953d0ec642ef4fc618ce963dbcd
    Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/7124103
    Reviewed-by: Toon Verwaest <verwaest@chromium.org>
    Commit-Queue: Erik Corry <erikcorry@chromium.org>
    Reviewed-by: Erik Corry <erikcorry@chromium.org>
    Cr-Commit-Position: refs/heads/main@{#103542}

Refs: https://github.com/v8/v8/commit/64b36b44117949fe03df33d077117e7bd6257669
PR-URL: https://github.com/nodejs/node/pull/61712
Reviewed-By: Rafael Gonzaga <rafael.nunu@hotmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
This commit is contained in:
Rafael Magrin authored and Antoine du Hamel committed 2026-02-19 11:13:47 +01:00
1 parent 608736e19e
commit 7d63a2df93
2 files changed
+31 -1

No files matched your search

+20 -1
View File
@@ -206,6 +206,16 @@ bool Utf8::IsValidCharacter(uchar c) {
c != kBadChar);
}
template <>
bool Utf8::IsAsciiOneByteString<uint8_t>(const uint8_t* buffer, size_t size) {
return simdutf::validate_ascii(reinterpret_cast<const char*>(buffer), size);
}
template <>
bool Utf8::IsAsciiOneByteString<uint16_t>(const uint16_t* buffer, size_t size) {
return false;
}
template <typename Char>
Utf8::EncodingResult Utf8::Encode(v8::base::Vector<const Char> string,
char* buffer, size_t capacity,
@@ -221,8 +231,17 @@ Utf8::EncodingResult Utf8::Encode(v8::base::Vector<const Char> string,
const Char* characters = string.begin();
size_t content_capacity = capacity - write_null;
CHECK_LE(content_capacity, capacity);
uint16_t last = Utf16::kNoPreviousCharacter;
size_t read_index = 0;
if (kSourceIsOneByte) {
size_t writeable = std::min(string.size(), content_capacity);
// Just memcpy when possible.
if (writeable > 0 && Utf8::IsAsciiOneByteString(characters, writeable)) {
memcpy(buffer, characters, writeable);
read_index = writeable;
write_index = writeable;
}
}
uint16_t last = Utf16::kNoPreviousCharacter;
for (; read_index < string.size(); read_index++) {
Char character = characters[read_index];
+11
View File
@@ -212,6 +212,9 @@ class V8_EXPORT_PRIVATE Utf8 {
// - valid code point range.
static bool ValidateEncoding(const uint8_t* str, size_t length);
template <typename Char>
static bool IsAsciiOneByteString(const Char* buffer, size_t size);
// Encode the given characters as Utf8 into the provided output buffer.
struct EncodingResult {
size_t bytes_written;
@@ -223,6 +226,14 @@ class V8_EXPORT_PRIVATE Utf8 {
bool replace_invalid_utf8);
};
template <>
inline bool Utf8::IsAsciiOneByteString<uint8_t>(const uint8_t* buffer,
size_t size);
template <>
inline bool Utf8::IsAsciiOneByteString<uint16_t>(const uint16_t* buffer,
size_t size);
#if V8_ENABLE_WEBASSEMBLY
class V8_EXPORT_PRIVATE Wtf8 {
public: