summaryrefslogtreecommitdiffstats
path: root/src/corelib
diff options
context:
space:
mode:
authorMarc Mutz <marc.mutz@kdab.com>2020-05-06 14:06:21 +0200
committerMarc Mutz <marc.mutz@kdab.com>2020-05-12 11:49:38 +0200
commit11dc9454037fd3c5d69328d7babd86d34fd2c5d1 (patch)
tree823314d8ec37fb28380b7f0f2322fc28ca7f81de /src/corelib
parent5bd7668403761fae0eb434ae7f7b9ce99f894802 (diff)
Port qustrlen and qustrchr to char16_t
Fix callers. Change-Id: Iaf604c890941aa3de3bd31da300b2066e65968ed Reviewed-by: Lars Knoll <lars.knoll@qt.io>
Diffstat (limited to 'src/corelib')
-rw-r--r--src/corelib/io/qurlrecode.cpp2
-rw-r--r--src/corelib/text/qstring.cpp28
-rw-r--r--src/corelib/text/qstringalgorithms.h4
-rw-r--r--src/corelib/text/qstringview.h4
4 files changed, 19 insertions, 19 deletions
diff --git a/src/corelib/io/qurlrecode.cpp b/src/corelib/io/qurlrecode.cpp
index 35ede8d078..4e1056f019 100644
--- a/src/corelib/io/qurlrecode.cpp
+++ b/src/corelib/io/qurlrecode.cpp
@@ -581,7 +581,7 @@ static bool simdCheckNonEncoded(...)
static int decode(QString &appendTo, const ushort *begin, const ushort *end)
{
// fast check whether there's anything to be decoded in the first place
- const ushort *input = QtPrivate::qustrchr(QStringView(begin, end), '%');
+ const ushort *input = reinterpret_cast<const ushort*>(QtPrivate::qustrchr(QStringView(begin, end), '%'));
if (Q_LIKELY(input == end))
return 0; // nothing to do, it was already decoded!
diff --git a/src/corelib/text/qstring.cpp b/src/corelib/text/qstring.cpp
index f07f25b8dd..077097e3fd 100644
--- a/src/corelib/text/qstring.cpp
+++ b/src/corelib/text/qstring.cpp
@@ -169,7 +169,7 @@ static inline bool qt_ends_with(QStringView haystack, QChar needle, Qt::CaseSens
// this won't crash nor produce incorrect results
__attribute__((__no_sanitize_address__))
#endif
-qsizetype QtPrivate::qustrlen(const ushort *str) noexcept
+qsizetype QtPrivate::qustrlen(const char16_t *str) noexcept
{
qsizetype result = 0;
@@ -177,7 +177,7 @@ qsizetype QtPrivate::qustrlen(const ushort *str) noexcept
// find the 16-byte alignment immediately prior or equal to str
quintptr misalignment = quintptr(str) & 0xf;
Q_ASSERT((misalignment & 1) == 0);
- const ushort *ptr = str - (misalignment / 2);
+ const char16_t *ptr = str - (misalignment / 2);
// load 16 bytes and see if we have a null
// (aligned loads can never segfault)
@@ -207,7 +207,7 @@ qsizetype QtPrivate::qustrlen(const ushort *str) noexcept
return ptr - str + idx / 2;
#endif
- if (sizeof(wchar_t) == sizeof(ushort))
+ if (sizeof(wchar_t) == sizeof(char16_t))
return wcslen(reinterpret_cast<const wchar_t *>(str));
while (*str++)
@@ -266,10 +266,10 @@ inline RetType UnrollTailLoop<0>::exec(Number, RetType returnIfExited, Functor1,
* character is not found, this function returns a pointer to the end of the
* string -- that is, \c{str.end()}.
*/
-const ushort *QtPrivate::qustrchr(QStringView str, ushort c) noexcept
+const char16_t *QtPrivate::qustrchr(QStringView str, char16_t c) noexcept
{
- const ushort *n = reinterpret_cast<const ushort *>(str.begin());
- const ushort *e = reinterpret_cast<const ushort *>(str.end());
+ const char16_t *n = str.utf16();
+ const char16_t *e = n + str.size();
#ifdef __SSE2__
bool loops = true;
@@ -278,7 +278,7 @@ const ushort *QtPrivate::qustrchr(QStringView str, ushort c) noexcept
# if defined(__AVX2__) && !defined(__OPTIMIZE_SIZE__)
// we're going to read n[0..15] (32 bytes)
__m256i mch256 = _mm256_set1_epi32(c | (c << 16));
- for (const ushort *next = n + 16; next <= e; n = next, next += 16) {
+ for (const char16_t *next = n + 16; next <= e; n = next, next += 16) {
__m256i data = _mm256_loadu_si256(reinterpret_cast<const __m256i *>(n));
__m256i result = _mm256_cmpeq_epi16(data, mch256);
uint mask = uint(_mm256_movemask_epi8(result));
@@ -304,7 +304,7 @@ const ushort *QtPrivate::qustrchr(QStringView str, ushort c) noexcept
};
// we're going to read n[0..7] (16 bytes)
- for (const ushort *next = n + 8; next <= e; n = next, next += 8) {
+ for (const char16_t *next = n + 8; next <= e; n = next, next += 8) {
__m128i data = _mm_loadu_si128(reinterpret_cast<const __m128i *>(n));
if (hasMatch(data, 0xffff))
return n;
@@ -332,8 +332,8 @@ const ushort *QtPrivate::qustrchr(QStringView str, ushort c) noexcept
#elif defined(__ARM_NEON__) && defined(Q_PROCESSOR_ARM_64) // vaddv is only available on Aarch64
const uint16x8_t vmask = { 1, 1 << 1, 1 << 2, 1 << 3, 1 << 4, 1 << 5, 1 << 6, 1 << 7 };
const uint16x8_t ch_vec = vdupq_n_u16(c);
- for (const ushort *next = n + 8; next <= e; n = next, next += 8) {
- uint16x8_t data = vld1q_u16(n);
+ for (const char16_t *next = n + 8; next <= e; n = next, next += 8) {
+ uint16x8_t data = vld1q_u16(reinterpret_cast<const uint16_t *>(n));
uint mask = vaddvq_u16(vandq_u16(vceqq_u16(data, ch_vec), vmask));
if (ushort(mask)) {
// found a match
@@ -11956,10 +11956,10 @@ static inline qsizetype qFindChar(QStringView str, QChar ch, qsizetype from, Qt:
if (from < 0)
from = qMax(from + str.size(), qsizetype(0));
if (from < str.size()) {
- const ushort *s = (const ushort *)str.data();
- ushort c = ch.unicode();
- const ushort *n = s + from;
- const ushort *e = s + str.size();
+ const char16_t *s = str.utf16();
+ char16_t c = ch.unicode();
+ const char16_t *n = s + from;
+ const char16_t *e = s + str.size();
if (cs == Qt::CaseSensitive) {
n = QtPrivate::qustrchr(QStringView(n, e), c);
if (n != e)
diff --git a/src/corelib/text/qstringalgorithms.h b/src/corelib/text/qstringalgorithms.h
index 0b7774b4f3..86bacdccad 100644
--- a/src/corelib/text/qstringalgorithms.h
+++ b/src/corelib/text/qstringalgorithms.h
@@ -56,8 +56,8 @@ template <typename T> class QVector;
namespace QtPrivate {
-Q_REQUIRED_RESULT Q_CORE_EXPORT Q_DECL_PURE_FUNCTION qsizetype qustrlen(const ushort *str) noexcept;
-Q_REQUIRED_RESULT Q_CORE_EXPORT Q_DECL_PURE_FUNCTION const ushort *qustrchr(QStringView str, ushort ch) noexcept;
+Q_REQUIRED_RESULT Q_CORE_EXPORT Q_DECL_PURE_FUNCTION qsizetype qustrlen(const char16_t *str) noexcept;
+Q_REQUIRED_RESULT Q_CORE_EXPORT Q_DECL_PURE_FUNCTION const char16_t *qustrchr(QStringView str, char16_t ch) noexcept;
Q_REQUIRED_RESULT Q_CORE_EXPORT Q_DECL_PURE_FUNCTION int compareStrings(QStringView lhs, QStringView rhs, Qt::CaseSensitivity cs = Qt::CaseSensitive) noexcept;
Q_REQUIRED_RESULT Q_CORE_EXPORT Q_DECL_PURE_FUNCTION int compareStrings(QStringView lhs, QLatin1String rhs, Qt::CaseSensitivity cs = Qt::CaseSensitive) noexcept;
diff --git a/src/corelib/text/qstringview.h b/src/corelib/text/qstringview.h
index b3206cc6e7..bc2c25f83d 100644
--- a/src/corelib/text/qstringview.h
+++ b/src/corelib/text/qstringview.h
@@ -167,11 +167,11 @@ private:
return result;
}
#endif
- return QtPrivate::qustrlen(reinterpret_cast<const ushort *>(str));
+ return QtPrivate::qustrlen(reinterpret_cast<const char16_t *>(str));
}
static qsizetype lengthHelperPointer(const QChar *str) noexcept
{
- return QtPrivate::qustrlen(reinterpret_cast<const ushort *>(str));
+ return QtPrivate::qustrlen(reinterpret_cast<const char16_t *>(str));
}
template <typename Char>