Commit 93ccfb74 authored by Toon Verwaest's avatar Toon Verwaest Committed by Commit Bot

Reland "[runtime] Speed up String::IsOneByte"

Check uintptr_t sized blocks of UTF16 chars at a time similar to NonAsciiStart.

Fix readds the length precheck so we won't read out of bounds while aligning
the start.

Change-Id: Iaea901945a2445ba5bf50c67a6211356697ed1fd
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1622115
Commit-Queue: Toon Verwaest <verwaest@chromium.org>
Commit-Queue: Igor Sheludko <ishell@chromium.org>
Auto-Submit: Toon Verwaest <verwaest@chromium.org>
Reviewed-by: 's avatarIgor Sheludko <ishell@chromium.org>
Cr-Commit-Position: refs/heads/master@{#61700}
parent 8298e1c8
......@@ -381,12 +381,42 @@ class String : public Name {
}
static inline int NonOneByteStart(const uc16* chars, int length) {
const uc16* limit = chars + length;
const uc16* start = chars;
DCHECK(IsAligned(reinterpret_cast<Address>(chars), sizeof(uc16)));
const uint16_t* start = chars;
const uint16_t* limit = chars + length;
if (static_cast<size_t>(length) >= kUIntptrSize) {
// Check unaligned chars.
while (!IsAligned(reinterpret_cast<Address>(chars), kUIntptrSize)) {
if (*chars > unibrow::Latin1::kMaxChar) {
return static_cast<int>(chars - start);
}
++chars;
}
// Check aligned words.
STATIC_ASSERT(unibrow::Latin1::kMaxChar == 0xFF);
#ifdef V8_TARGET_LITTLE_ENDIAN
const uintptr_t non_one_byte_mask = kUintptrAllBitsSet / 0xFFFF * 0xFF00;
#else
const uintptr_t non_one_byte_mask = kUintptrAllBitsSet / 0xFFFF * 0x00FF;
#endif
while (chars + sizeof(uintptr_t) <= limit) {
if (*reinterpret_cast<const uintptr_t*>(chars) & non_one_byte_mask) {
break;
}
chars += (sizeof(uintptr_t) / sizeof(uc16));
}
}
// Check remaining unaligned chars, or find non-one-byte char in word.
while (chars < limit) {
if (*chars > kMaxOneByteCharCodeU) return static_cast<int>(chars - start);
if (*chars > unibrow::Latin1::kMaxChar) {
return static_cast<int>(chars - start);
}
++chars;
}
return static_cast<int>(chars - start);
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment