| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 608736e commit 7d63a2d
2 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -206,6 +206,16 @@ bool Utf8::IsValidCharacter(uchar c) { | |||
| 206 | 206 | c != kBadChar); | |
| 207 | 207 | } | |
| 208 | 208 | ||
| 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 | + | ||
| 209 | 219 | template <typename Char> | |
| 210 | 220 | Utf8::EncodingResult Utf8::Encode(v8::base::Vector<const Char> string, | |
| 211 | 221 | char* buffer, size_t capacity, | |
@@ -221,8 +231,17 @@ Utf8::EncodingResult Utf8::Encode(v8::base::Vector<const Char> string, | |||
| 221 | 231 | const Char* characters = string.begin(); | |
| 222 | 232 | size_t content_capacity = capacity - write_null; | |
| 223 | 233 | CHECK_LE(content_capacity, capacity); | |
| 224 | - uint16_t last = Utf16::kNoPreviousCharacter; | ||
| 225 | 234 | 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; | ||
| 226 | 245 | for (; read_index < string.size(); read_index++) { | |
| 227 | 246 | Char character = characters[read_index]; | |
| 228 | 247 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -212,6 +212,9 @@ class V8_EXPORT_PRIVATE Utf8 { | |||
| 212 | 212 | // - valid code point range. | |
| 213 | 213 | static bool ValidateEncoding(const uint8_t* str, size_t length); | |
| 214 | 214 | ||
| 215 | + template <typename Char> | ||
| 216 | + static bool IsAsciiOneByteString(const Char* buffer, size_t size); | ||
| 217 | + | ||
| 215 | 218 | // Encode the given characters as Utf8 into the provided output buffer. | |
| 216 | 219 | struct EncodingResult { | |
| 217 | 220 | size_t bytes_written; | |
@@ -223,6 +226,14 @@ class V8_EXPORT_PRIVATE Utf8 { | |||
| 223 | 226 | bool replace_invalid_utf8); | |
| 224 | 227 | }; | |
| 225 | 228 | ||
| 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 | + | ||
| 226 | 237 | #if V8_ENABLE_WEBASSEMBLY | |
| 227 | 238 | class V8_EXPORT_PRIVATE Wtf8 { | |
| 228 | 239 | public: | |
| Back | FazBrowse Home | New Git URL |
0 commit comments