Skip to content

Commit 08848a6

Browse files
Dan Carneyrmagrin
authored andcommitted
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: v8/v8@64b36b4
1 parent 9afa802 commit 08848a6

File tree

3 files changed

+31
-2
lines changed

3 files changed

+31
-2
lines changed

common.gypi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838

3939
# Reset this number to 0 on major V8 upgrades.
4040
# Increment by one for each non-official patch applied to deps/v8.
41-
'v8_embedder_string': '-node.11',
41+
'v8_embedder_string': '-node.12',
4242

4343
##### V8 defaults for Node.js #####
4444

deps/v8/src/strings/unicode-inl.h

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,16 @@ bool Utf8::IsValidCharacter(uchar c) {
206206
c != kBadChar);
207207
}
208208

209+
template <>
210+
bool Utf8::IsAsciiOneByteString<uint8_t>(const uint8_t* buffer, size_t size) {
211+
return simdutf::validate_ascii(reinterpret_cast<const char*>(buffer), size);
212+
}
213+
214+
template <>
215+
bool Utf8::IsAsciiOneByteString<uint16_t>(const uint16_t* buffer, size_t size) {
216+
return false;
217+
}
218+
209219
template <typename Char>
210220
Utf8::EncodingResult Utf8::Encode(v8::base::Vector<const Char> string,
211221
char* buffer, size_t capacity,
@@ -221,8 +231,17 @@ Utf8::EncodingResult Utf8::Encode(v8::base::Vector<const Char> string,
221231
const Char* characters = string.begin();
222232
size_t content_capacity = capacity - write_null;
223233
CHECK_LE(content_capacity, capacity);
224-
uint16_t last = Utf16::kNoPreviousCharacter;
225234
size_t read_index = 0;
235+
if (kSourceIsOneByte) {
236+
size_t writeable = std::min(string.size(), content_capacity);
237+
// Just memcpy when possible.
238+
if (writeable > 0 && Utf8::IsAsciiOneByteString(characters, writeable)) {
239+
memcpy(buffer, characters, writeable);
240+
read_index = writeable;
241+
write_index = writeable;
242+
}
243+
}
244+
uint16_t last = Utf16::kNoPreviousCharacter;
226245
for (; read_index < string.size(); read_index++) {
227246
Char character = characters[read_index];
228247

deps/v8/src/strings/unicode.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,16 @@ class V8_EXPORT_PRIVATE Utf8 {
212212
// - valid code point range.
213213
static bool ValidateEncoding(const uint8_t* str, size_t length);
214214

215+
template <typename Char>
216+
static bool IsAsciiOneByteString(const Char* buffer, size_t size);
217+
218+
template <>
219+
inline bool IsAsciiOneByteString<uint8_t>(const uint8_t* buffer, size_t size);
220+
221+
template <>
222+
inline bool IsAsciiOneByteString<uint16_t>(const uint16_t* buffer,
223+
size_t size);
224+
215225
// Encode the given characters as Utf8 into the provided output buffer.
216226
struct EncodingResult {
217227
size_t bytes_written;

0 commit comments

Comments
 (0)