QString: use char16_t in isAscii() instead of QChar
Drive-by simple clarification of the code that needed to be touched anyway. Pick-to: 6.3 6.2 Change-Id: Ib42b3adc93bf4d43bd55fffd16c14f984b0fb592 Reviewed-by: Marc Mutz <marc.mutz@qt.io>
This commit is contained in:
parent
1a9e7a3aad
commit
8db16bfa7e
@ -542,19 +542,19 @@ bool QtPrivate::isAscii(QLatin1String s) noexcept
|
|||||||
return qt_is_ascii(ptr, end);
|
return qt_is_ascii(ptr, end);
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool isAscii(const QChar *&ptr, const QChar *end)
|
static bool isAscii_helper(const char16_t *&ptr, const char16_t *end)
|
||||||
{
|
{
|
||||||
#ifdef __SSE2__
|
#ifdef __SSE2__
|
||||||
const char *ptr8 = reinterpret_cast<const char *>(ptr);
|
const char *ptr8 = reinterpret_cast<const char *>(ptr);
|
||||||
const char *end8 = reinterpret_cast<const char *>(end);
|
const char *end8 = reinterpret_cast<const char *>(end);
|
||||||
bool ok = simdTestMask(ptr8, end8, 0xff80ff80);
|
bool ok = simdTestMask(ptr8, end8, 0xff80ff80);
|
||||||
ptr = reinterpret_cast<const QChar *>(ptr8);
|
ptr = reinterpret_cast<const char16_t *>(ptr8);
|
||||||
if (!ok)
|
if (!ok)
|
||||||
return false;
|
return false;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
while (ptr != end) {
|
while (ptr != end) {
|
||||||
if (ptr->unicode() & 0xff80)
|
if (*ptr & 0xff80)
|
||||||
return false;
|
return false;
|
||||||
++ptr;
|
++ptr;
|
||||||
}
|
}
|
||||||
@ -563,27 +563,27 @@ static bool isAscii(const QChar *&ptr, const QChar *end)
|
|||||||
|
|
||||||
bool QtPrivate::isAscii(QStringView s) noexcept
|
bool QtPrivate::isAscii(QStringView s) noexcept
|
||||||
{
|
{
|
||||||
const QChar *ptr = s.begin();
|
const char16_t *ptr = s.utf16();
|
||||||
const QChar *end = s.end();
|
const char16_t *end = ptr + s.size();
|
||||||
|
|
||||||
return isAscii(ptr, end);
|
return isAscii_helper(ptr, end);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool QtPrivate::isLatin1(QStringView s) noexcept
|
bool QtPrivate::isLatin1(QStringView s) noexcept
|
||||||
{
|
{
|
||||||
const QChar *ptr = s.begin();
|
const char16_t *ptr = s.utf16();
|
||||||
const QChar *end = s.end();
|
const char16_t *end = ptr + s.size();
|
||||||
|
|
||||||
#ifdef __SSE2__
|
#ifdef __SSE2__
|
||||||
const char *ptr8 = reinterpret_cast<const char *>(ptr);
|
const char *ptr8 = reinterpret_cast<const char *>(ptr);
|
||||||
const char *end8 = reinterpret_cast<const char *>(end);
|
const char *end8 = reinterpret_cast<const char *>(end);
|
||||||
if (!simdTestMask(ptr8, end8, 0xff00ff00))
|
if (!simdTestMask(ptr8, end8, 0xff00ff00))
|
||||||
return false;
|
return false;
|
||||||
ptr = reinterpret_cast<const QChar *>(ptr8);
|
ptr = reinterpret_cast<const char16_t *>(ptr8);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
while (ptr != end) {
|
while (ptr != end) {
|
||||||
if ((*ptr++).unicode() > 0xff)
|
if (*ptr++ > 0xff)
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
@ -7702,11 +7702,15 @@ QString QString::repeated(qsizetype times) const
|
|||||||
|
|
||||||
void qt_string_normalize(QString *data, QString::NormalizationForm mode, QChar::UnicodeVersion version, qsizetype from)
|
void qt_string_normalize(QString *data, QString::NormalizationForm mode, QChar::UnicodeVersion version, qsizetype from)
|
||||||
{
|
{
|
||||||
const QChar *p = data->constData() + from;
|
{
|
||||||
if (isAscii(p, p + data->length() - from))
|
// check if it's fully ASCII first, because then we have no work
|
||||||
return;
|
auto start = reinterpret_cast<const char16_t *>(data->constData());
|
||||||
if (p > data->constData() + from)
|
const char16_t *p = start + from;
|
||||||
from = p - data->constData() - 1; // need one before the non-ASCII to perform NFC
|
if (isAscii_helper(p, p + data->length() - from))
|
||||||
|
return;
|
||||||
|
if (p > start + from)
|
||||||
|
from = p - start - 1; // need one before the non-ASCII to perform NFC
|
||||||
|
}
|
||||||
|
|
||||||
if (version == QChar::Unicode_Unassigned) {
|
if (version == QChar::Unicode_Unassigned) {
|
||||||
version = QChar::currentUnicodeVersion();
|
version = QChar::currentUnicodeVersion();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user