From 3ea09e447487a26bf6c833dc0707a83844190777 Mon Sep 17 00:00:00 2001 From: Shawn Rutledge Date: Mon, 28 Aug 2017 16:46:54 +0200 Subject: QLocale docs: remove useless \sa links It's true that formattedDataSize is useful for formatting file sizes from QFileInfo, but these links don't make sense here, and also cause qdoc warnings due to lack of class scoping. Change-Id: I9dd28200aa9d0da048db0c02ac66dc20c1b42e5c Reviewed-by: Friedemann Kleint --- src/corelib/tools/qlocale.cpp | 2 -- 1 file changed, 2 deletions(-) (limited to 'src/corelib/tools') diff --git a/src/corelib/tools/qlocale.cpp b/src/corelib/tools/qlocale.cpp index 5db181885c..9a46018ede 100644 --- a/src/corelib/tools/qlocale.cpp +++ b/src/corelib/tools/qlocale.cpp @@ -3814,8 +3814,6 @@ QString QLocale::toCurrencyString(double value, const QString &symbol, int preci 1000. DataSizeIecFormat uses the new IEC standard quantifiers Ki, Mi and so on, whereas DataSizeSIFormat uses and DataSizeTraditionalFormat abuses the older SI quantifiers k, M, etc. - - \sa refresh(), caching() */ QString QLocale::formattedDataSize(qint64 bytes, int precision, DataSizeFormats format) { -- cgit v1.2.3 From 3b61cd6ad738b8479bf216dcf736bb935e8812df Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Sun, 20 Aug 2017 14:22:44 -0700 Subject: QStringView: De-inline the length calculation so we can use SSE2 Performance is more important in this case than the theoretical benefit of constexpr. This commit implements the SSE2 search for 16-bit null and it might be possible to implement the equivalent for AArch64 (investigation required). It also adds a fallback to wcslen() for systems where wchar_t is short (non-x86 Windows or 32-bit x86 build with -no-sse2). We can re-add the constexpr loop once the C++ language has a way of overloading constexpr and non-constexpr. GCC has a non-standard way to do that with __builtin_constant_p, which is also implemented in this commit, but note that the inline function is still not constexpr. Change-Id: I6e9274c1e7444ad48c81fffd14dcaacafda5ebdc Reviewed-by: Oswald Buddenhagen Reviewed-by: Thiago Macieira --- src/corelib/tools/qstring.cpp | 38 +++++++++++++++++++++++++++++++++++ src/corelib/tools/qstringalgorithms.h | 2 ++ src/corelib/tools/qstringview.h | 22 +++++++++++--------- 3 files changed, 52 insertions(+), 10 deletions(-) (limited to 'src/corelib/tools') diff --git a/src/corelib/tools/qstring.cpp b/src/corelib/tools/qstring.cpp index 3826d7531a..a0c309c1cf 100644 --- a/src/corelib/tools/qstring.cpp +++ b/src/corelib/tools/qstring.cpp @@ -72,6 +72,7 @@ #include #include #include +#include #include "qchar.cpp" #include "qstringmatcher.cpp" @@ -159,6 +160,43 @@ static inline bool qt_ends_with(QStringView haystack, QStringView needle, Qt::Ca static inline bool qt_ends_with(QStringView haystack, QLatin1String needle, Qt::CaseSensitivity cs); static inline bool qt_ends_with(QStringView haystack, QChar needle, Qt::CaseSensitivity cs); +qssize_t qustrlen(const ushort *str) Q_DECL_NOTHROW +{ + qssize_t result = 0; + +#ifdef __SSE2__ + // progress until we get an aligned pointer + const ushort *ptr = str; + while (*ptr && quintptr(ptr) % 16) + ++ptr; + if (*ptr == 0) + return ptr - str; + + // load 16 bytes and see if we have a null + // (aligned loads can never segfault) + int mask; + const __m128i zeroes = _mm_setzero_si128(); + do { + __m128i data = _mm_load_si128(reinterpret_cast(ptr)); + ptr += 8; + + __m128i comparison = _mm_cmpeq_epi16(data, zeroes); + mask = _mm_movemask_epi8(comparison); + } while (mask == 0); + + // found a null + uint idx = qCountTrailingZeroBits(quint32(mask)); + return ptr - str - 8 + idx / 2; +#endif + + if (sizeof(wchar_t) == sizeof(ushort)) + return wcslen(reinterpret_cast(str)); + + while (*str++) + ++result; + return result; +} + #if defined(Q_COMPILER_LAMBDA) && !defined(__OPTIMIZE_SIZE__) namespace { template struct UnrollTailLoop diff --git a/src/corelib/tools/qstringalgorithms.h b/src/corelib/tools/qstringalgorithms.h index e1b8b90428..eaa7207bec 100644 --- a/src/corelib/tools/qstringalgorithms.h +++ b/src/corelib/tools/qstringalgorithms.h @@ -53,6 +53,8 @@ class QLatin1String; class QStringView; template class QVector; +Q_REQUIRED_RESULT Q_CORE_EXPORT Q_DECL_PURE_FUNCTION qssize_t qustrlen(const ushort *str) Q_DECL_NOTHROW; + Q_REQUIRED_RESULT Q_CORE_EXPORT Q_DECL_PURE_FUNCTION int qCompareStrings(QStringView lhs, QStringView rhs, Qt::CaseSensitivity cs = Qt::CaseSensitive) Q_DECL_NOTHROW; Q_REQUIRED_RESULT Q_CORE_EXPORT Q_DECL_PURE_FUNCTION int qCompareStrings(QStringView lhs, QLatin1String rhs, Qt::CaseSensitivity cs = Qt::CaseSensitive) Q_DECL_NOTHROW; Q_REQUIRED_RESULT Q_CORE_EXPORT Q_DECL_PURE_FUNCTION int qCompareStrings(QLatin1String lhs, QStringView rhs, Qt::CaseSensitivity cs = Qt::CaseSensitive) Q_DECL_NOTHROW; diff --git a/src/corelib/tools/qstringview.h b/src/corelib/tools/qstringview.h index 24be441b00..764da71d0b 100644 --- a/src/corelib/tools/qstringview.h +++ b/src/corelib/tools/qstringview.h @@ -143,20 +143,22 @@ private: { return qssize_t(N - 1); } + template - static Q_DECL_RELAXED_CONSTEXPR qssize_t lengthHelperPointer(const Char *str) Q_DECL_NOTHROW + static qssize_t lengthHelperPointer(const Char *str) Q_DECL_NOTHROW { - qssize_t result = 0; - while (*str++) - ++result; - return result; +#if defined(Q_CC_GNU) && !defined(Q_CC_CLANG) && !defined(Q_CC_INTEL) + if (__builtin_constant_p(*str)) { + qssize_t result = 0; + while (*str++) + ++result; + } +#endif + return qustrlen(reinterpret_cast(str)); } - static Q_DECL_RELAXED_CONSTEXPR qssize_t lengthHelperPointer(const QChar *str) Q_DECL_NOTHROW + static qssize_t lengthHelperPointer(const QChar *str) Q_DECL_NOTHROW { - qssize_t result = 0; - while (!str++->isNull()) - ++result; - return result; + return qustrlen(reinterpret_cast(str)); } template -- cgit v1.2.3 From 81a19050d8127e7b05006f793a8797c8f5248191 Mon Sep 17 00:00:00 2001 From: Giuseppe D'Angelo Date: Tue, 12 Sep 2017 11:42:23 +0100 Subject: QSharedPointer: fix undefined behavior in operator< Pointers belonging to different arrays must be compared using std::less. Change-Id: Ib77af7b1b2da58d7243fa77273a8a45ee9035a1a Reviewed-by: Thiago Macieira --- src/corelib/tools/qsharedpointer_impl.h | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'src/corelib/tools') diff --git a/src/corelib/tools/qsharedpointer_impl.h b/src/corelib/tools/qsharedpointer_impl.h index 15573c5588..ede54c155d 100644 --- a/src/corelib/tools/qsharedpointer_impl.h +++ b/src/corelib/tools/qsharedpointer_impl.h @@ -850,17 +850,20 @@ Q_INLINE_TEMPLATE typename QSharedPointer::difference_type operator-(T *ptr1, template Q_INLINE_TEMPLATE bool operator<(const QSharedPointer &ptr1, const QSharedPointer &ptr2) { - return ptr1.data() < ptr2.data(); + using CT = typename std::common_type::type; + return std::less()(ptr1.data(), ptr2.data()); } template Q_INLINE_TEMPLATE bool operator<(const QSharedPointer &ptr1, X *ptr2) { - return ptr1.data() < ptr2; + using CT = typename std::common_type::type; + return std::less()(ptr1.data(), ptr2); } template Q_INLINE_TEMPLATE bool operator<(T *ptr1, const QSharedPointer &ptr2) { - return ptr1 < ptr2.data(); + using CT = typename std::common_type::type; + return std::less()(ptr1, ptr2.data()); } // -- cgit v1.2.3 From 282065d443c2a2d6b9e32d786c2c1c7552ba3cb5 Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Tue, 19 Sep 2017 11:47:38 -0700 Subject: QRandomGenerator: update API to better name MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit "generate" is better than "get", and we already have "generate(it, it)" which uses std::generate(). This changes: - get32() → generate() - get64() → generate64() and QRandomGenerator64::generate() - getReal() → generateDouble() Change-Id: I6e1fe42ae4b742a7b811fffd14e5d7bd69abcdb3 Reviewed-by: Lars Knoll --- src/corelib/tools/qhash.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/corelib/tools') diff --git a/src/corelib/tools/qhash.cpp b/src/corelib/tools/qhash.cpp index e336b7e618..485c6591c2 100644 --- a/src/corelib/tools/qhash.cpp +++ b/src/corelib/tools/qhash.cpp @@ -296,7 +296,7 @@ static uint qt_create_qhash_seed() return seed; } - seed = QRandomGenerator::get32(); + seed = QRandomGenerator::generate(); #endif // QT_BOOTSTRAPPED return seed; -- cgit v1.2.3