@@ -6491,34 +6491,38 @@ static bool FastAsciiConvert(char* dst,
64916491 bool changed = false;
64926492 uintptr_t or_acc = 0;
64936493 const char* const limit = src + length;
6494- #ifdef V8_HOST_CAN_READ_UNALIGNED
6495- // Process the prefix of the input that requires no conversion one
6496- // (machine) word at a time.
6497- while (src <= limit - sizeof(uintptr_t)) {
6498- const uintptr_t w = *reinterpret_cast<const uintptr_t*>(src);
6499- or_acc |= w;
6500- if (AsciiRangeMask(w, lo, hi) != 0) {
6501- changed = true;
6502- break;
6494+
6495+ // dst is newly allocated and always aligned.
6496+ DCHECK(IsAligned(reinterpret_cast<intptr_t>(dst), sizeof(uintptr_t)));
6497+ // Only attempt processing one word at a time if src is also aligned.
6498+ if (IsAligned(reinterpret_cast<intptr_t>(src), sizeof(uintptr_t))) {
6499+ // Process the prefix of the input that requires no conversion one aligned
6500+ // (machine) word at a time.
6501+ while (src <= limit - sizeof(uintptr_t)) {
6502+ const uintptr_t w = *reinterpret_cast<const uintptr_t*>(src);
6503+ or_acc |= w;
6504+ if (AsciiRangeMask(w, lo, hi) != 0) {
6505+ changed = true;
6506+ break;
6507+ }
6508+ *reinterpret_cast<uintptr_t*>(dst) = w;
6509+ src += sizeof(uintptr_t);
6510+ dst += sizeof(uintptr_t);
6511+ }
6512+ // Process the remainder of the input performing conversion when
6513+ // required one word at a time.
6514+ while (src <= limit - sizeof(uintptr_t)) {
6515+ const uintptr_t w = *reinterpret_cast<const uintptr_t*>(src);
6516+ or_acc |= w;
6517+ uintptr_t m = AsciiRangeMask(w, lo, hi);
6518+ // The mask has high (7th) bit set in every byte that needs
6519+ // conversion and we know that the distance between cases is
6520+ // 1 << 5.
6521+ *reinterpret_cast<uintptr_t*>(dst) = w ^ (m >> 2);
6522+ src += sizeof(uintptr_t);
6523+ dst += sizeof(uintptr_t);
65036524 }
6504- *reinterpret_cast<uintptr_t*>(dst) = w;
6505- src += sizeof(uintptr_t);
6506- dst += sizeof(uintptr_t);
6507- }
6508- // Process the remainder of the input performing conversion when
6509- // required one word at a time.
6510- while (src <= limit - sizeof(uintptr_t)) {
6511- const uintptr_t w = *reinterpret_cast<const uintptr_t*>(src);
6512- or_acc |= w;
6513- uintptr_t m = AsciiRangeMask(w, lo, hi);
6514- // The mask has high (7th) bit set in every byte that needs
6515- // conversion and we know that the distance between cases is
6516- // 1 << 5.
6517- *reinterpret_cast<uintptr_t*>(dst) = w ^ (m >> 2);
6518- src += sizeof(uintptr_t);
6519- dst += sizeof(uintptr_t);
65206525 }
6521- #endif
65226526 // Process the last few bytes of the input (or the whole input if
65236527 // unaligned access is not supported).
65246528 while (src < limit) {
@@ -6532,9 +6536,8 @@ static bool FastAsciiConvert(char* dst,
65326536 ++src;
65336537 ++dst;
65346538 }
6535- if ((or_acc & kAsciiMask) != 0) {
6536- return false;
6537- }
6539+
6540+ if ((or_acc & kAsciiMask) != 0) return false;
65386541
65396542 DCHECK(CheckFastAsciiConvert(
65406543 saved_dst, saved_src, length, changed, Converter::kIsToLower));
0 commit comments