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: Igor Sheludko <ishell@chromium.org> Cr-Commit-Position: refs/heads/master@{#61700}
This commit is contained in:
parent
8298e1c8aa
commit
93ccfb74db
@ -381,12 +381,42 @@ class String : public Name {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static inline int NonOneByteStart(const uc16* chars, int length) {
|
static inline int NonOneByteStart(const uc16* chars, int length) {
|
||||||
const uc16* limit = chars + length;
|
DCHECK(IsAligned(reinterpret_cast<Address>(chars), sizeof(uc16)));
|
||||||
const uc16* start = chars;
|
const uint16_t* start = chars;
|
||||||
while (chars < limit) {
|
const uint16_t* limit = chars + length;
|
||||||
if (*chars > kMaxOneByteCharCodeU) return static_cast<int>(chars - start);
|
|
||||||
|
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;
|
++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 > unibrow::Latin1::kMaxChar) {
|
||||||
|
return static_cast<int>(chars - start);
|
||||||
|
}
|
||||||
|
++chars;
|
||||||
|
}
|
||||||
|
|
||||||
return static_cast<int>(chars - start);
|
return static_cast<int>(chars - start);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user