GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — deps: V8: cherry-pick 64b36b441179 · nodejs/node@7d63a2d

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • deps/v8/src/strings
    • unicode-inl.h
    • unicode.h
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)
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.