diff options
author | Thiago Macieira <thiago.macieira@intel.com> | 2021-12-16 15:27:34 -0300 |
---|---|---|
committer | Qt Cherry-pick Bot <cherrypick_bot@qt-project.org> | 2021-12-18 23:45:24 +0000 |
commit | 87dd49ae9d74216e8f49d6b31ea5dc7f6bab21b1 (patch) | |
tree | 0a22a91dd268bda631d4c8d53721d978fa6a1ce7 /src/corelib/text | |
parent | 9b114e569afea5201d7d4ed094454f979de444f4 (diff) |
QString: use char16_t in isAscii() instead of QChar
Drive-by simple clarification of the code that needed to be touched
anyway.
Change-Id: Ib42b3adc93bf4d43bd55fffd16c14f984b0fb592
Reviewed-by: Marc Mutz <marc.mutz@qt.io>
(cherry picked from commit 8db16bfa7e2ebfcb710d8d9e885c2d54d7b29b4f)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
Diffstat (limited to 'src/corelib/text')
-rw-r--r-- | src/corelib/text/qstring.cpp | 34 |
1 files changed, 19 insertions, 15 deletions
diff --git a/src/corelib/text/qstring.cpp b/src/corelib/text/qstring.cpp index 04cc5cb080..1127cf610d 100644 --- a/src/corelib/text/qstring.cpp +++ b/src/corelib/text/qstring.cpp @@ -537,19 +537,19 @@ bool QtPrivate::isAscii(QLatin1String s) noexcept 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__ const char *ptr8 = reinterpret_cast<const char *>(ptr); const char *end8 = reinterpret_cast<const char *>(end); bool ok = simdTestMask(ptr8, end8, 0xff80ff80); - ptr = reinterpret_cast<const QChar *>(ptr8); + ptr = reinterpret_cast<const char16_t *>(ptr8); if (!ok) return false; #endif while (ptr != end) { - if (ptr->unicode() & 0xff80) + if (*ptr & 0xff80) return false; ++ptr; } @@ -558,27 +558,27 @@ static bool isAscii(const QChar *&ptr, const QChar *end) bool QtPrivate::isAscii(QStringView s) noexcept { - const QChar *ptr = s.begin(); - const QChar *end = s.end(); + const char16_t *ptr = s.utf16(); + const char16_t *end = ptr + s.size(); - return isAscii(ptr, end); + return isAscii_helper(ptr, end); } bool QtPrivate::isLatin1(QStringView s) noexcept { - const QChar *ptr = s.begin(); - const QChar *end = s.end(); + const char16_t *ptr = s.utf16(); + const char16_t *end = ptr + s.size(); #ifdef __SSE2__ const char *ptr8 = reinterpret_cast<const char *>(ptr); const char *end8 = reinterpret_cast<const char *>(end); if (!simdTestMask(ptr8, end8, 0xff00ff00)) return false; - ptr = reinterpret_cast<const QChar *>(ptr8); + ptr = reinterpret_cast<const char16_t *>(ptr8); #endif while (ptr != end) { - if ((*ptr++).unicode() > 0xff) + if (*ptr++ > 0xff) return false; } return true; @@ -7712,11 +7712,15 @@ QString QString::repeated(qsizetype times) const 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)) - return; - if (p > data->constData() + from) - from = p - data->constData() - 1; // need one before the non-ASCII to perform NFC + { + // check if it's fully ASCII first, because then we have no work + auto start = reinterpret_cast<const char16_t *>(data->constData()); + const char16_t *p = start + from; + 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) { version = QChar::currentUnicodeVersion(); |