Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 7d63a2d

Browse filesBrowse files
rmagrinaduh95
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 PR-URL: #61712 Reviewed-By: Rafael Gonzaga <rafael.nunu@hotmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
1 parent 608736e commit 7d63a2d
Copy full SHA for 7d63a2d

2 files changed

+31-1Lines changed: 31 additions & 1 deletion

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
Expand file treeCollapse file tree
Open diff view settings
Collapse file

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

Copy file name to clipboardExpand all lines: deps/v8/src/strings/unicode-inl.h
+20-1Lines 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

Collapse file

‎deps/v8/src/strings/unicode.h‎

Copy file name to clipboardExpand all lines: deps/v8/src/strings/unicode.h
+11Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,9 @@ 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+
215218
// Encode the given characters as Utf8 into the provided output buffer.
216219
struct EncodingResult {
217220
size_t bytes_written;
@@ -223,6 +226,14 @@ class V8_EXPORT_PRIVATE Utf8 {
223226
bool replace_invalid_utf8);
224227
};
225228

229+
template <>
230+
inline bool Utf8::IsAsciiOneByteString<uint8_t>(const uint8_t* buffer,
231+
size_t size);
232+
233+
template <>
234+
inline bool Utf8::IsAsciiOneByteString<uint16_t>(const uint16_t* buffer,
235+
size_t size);
236+
226237
#if V8_ENABLE_WEBASSEMBLY
227238
class V8_EXPORT_PRIVATE Wtf8 {
228239
public:

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.