summaryrefslogtreecommitdiffstats
path: root/src/corelib/tools/qstring.cpp
diff options
context:
space:
mode:
authorThiago Macieira <thiago.macieira@intel.com>2018-05-09 19:56:30 -0700
committerThiago Macieira <thiago.macieira@intel.com>2018-05-15 23:04:46 +0000
commit9d0907b07606ab4da16ae67aac9523fce7ff9525 (patch)
tree9a724ff20c5c76778b12c43aac3ced08653b2c81 /src/corelib/tools/qstring.cpp
parent65711d7aeac1b398c4aa45e5e73aeb500d6aab6b (diff)
QUrl: use the SIMD ASCII-checking code from the last commit
Improves performance a little. This is just because I can and the function is right there for the taking, as this qt_urlRecodeByteArray function is only used in deprecated QUrl code. Change-Id: I5d0ee9389a794d80983efffd152d290e570af387 Reviewed-by: Allan Sandfeld Jensen <allan.jensen@qt.io>
Diffstat (limited to 'src/corelib/tools/qstring.cpp')
-rw-r--r--src/corelib/tools/qstring.cpp25
1 files changed, 19 insertions, 6 deletions
diff --git a/src/corelib/tools/qstring.cpp b/src/corelib/tools/qstring.cpp
index 773b15032d4..719c685f697 100644
--- a/src/corelib/tools/qstring.cpp
+++ b/src/corelib/tools/qstring.cpp
@@ -333,11 +333,10 @@ static bool simdTestMask(const char *&ptr, const char *end, quint32 maskval)
}
#endif
-bool QtPrivate::isAscii(QLatin1String s) Q_DECL_NOTHROW
+// Note: ptr on output may be off by one and point to a preceding US-ASCII
+// character. Usually harmless.
+bool qt_is_ascii(const char *&ptr, const char *end) Q_DECL_NOTHROW
{
- const char *ptr = s.begin();
- const char *end = s.end();
-
#if defined(__AVX2__)
if (!simdTestMask(ptr, end, 0x80808080))
return false;
@@ -346,16 +345,22 @@ bool QtPrivate::isAscii(QLatin1String s) Q_DECL_NOTHROW
while (ptr + 16 < end) {
__m128i data = _mm_loadu_si128(reinterpret_cast<const __m128i *>(ptr));
quint32 mask = _mm_movemask_epi8(data);
- if (mask)
+ if (mask) {
+ uint idx = qCountTrailingZeroBits(mask);
+ ptr += idx;
return false;
+ }
ptr += 16;
}
#endif
while (ptr + 4 <= end) {
quint32 data = qFromUnaligned<quint32>(ptr);
- if (data & 0x80808080U)
+ if (data &= 0x80808080U) {
+ uint idx = qCountTrailingZeroBits(data);
+ ptr += idx / 8;
return false;
+ }
ptr += 4;
}
@@ -367,6 +372,14 @@ bool QtPrivate::isAscii(QLatin1String s) Q_DECL_NOTHROW
return true;
}
+bool QtPrivate::isAscii(QLatin1String s) Q_DECL_NOTHROW
+{
+ const char *ptr = s.begin();
+ const char *end = s.end();
+
+ return qt_is_ascii(ptr, end);
+}
+
static bool isAscii(const QChar *&ptr, const QChar *end)
{
#ifdef __SSE2__