summaryrefslogtreecommitdiffstats
path: root/src/corelib/tools
diff options
context:
space:
mode:
Diffstat (limited to 'src/corelib/tools')
-rw-r--r--src/corelib/tools/qalgorithms.h209
-rw-r--r--src/corelib/tools/qbytearray.cpp85
-rw-r--r--src/corelib/tools/qbytearray.h8
-rw-r--r--src/corelib/tools/qbytearray_mac.mm99
-rw-r--r--src/corelib/tools/qbytearraylist.h2
-rw-r--r--src/corelib/tools/qbytedata_p.h1
-rw-r--r--src/corelib/tools/qchar.h12
-rw-r--r--src/corelib/tools/qcollator_p.h1
-rw-r--r--src/corelib/tools/qcommandlineoption.cpp58
-rw-r--r--src/corelib/tools/qcommandlineoption.h16
-rw-r--r--src/corelib/tools/qcommandlineparser.cpp28
-rw-r--r--src/corelib/tools/qcryptographichash.h3
-rw-r--r--src/corelib/tools/qdatetime.cpp1051
-rw-r--r--src/corelib/tools/qdatetime.h89
-rw-r--r--src/corelib/tools/qdatetime_mac.mm74
-rw-r--r--src/corelib/tools/qdatetime_p.h71
-rw-r--r--src/corelib/tools/qdatetimeparser_p.h1
-rw-r--r--src/corelib/tools/qelapsedtimer.cpp267
-rw-r--r--src/corelib/tools/qelapsedtimer.h95
-rw-r--r--src/corelib/tools/qelapsedtimer_generic.cpp204
-rw-r--r--src/corelib/tools/qelapsedtimer_mac.cpp149
-rw-r--r--src/corelib/tools/qelapsedtimer_unix.cpp251
-rw-r--r--src/corelib/tools/qelapsedtimer_win.cpp193
-rw-r--r--src/corelib/tools/qfreelist_p.h1
-rw-r--r--src/corelib/tools/qharfbuzz_p.h2
-rw-r--r--src/corelib/tools/qhash.cpp20
-rw-r--r--src/corelib/tools/qhash.h21
-rw-r--r--src/corelib/tools/qline.cpp23
-rw-r--r--src/corelib/tools/qline.h14
-rw-r--r--src/corelib/tools/qlist.h5
-rw-r--r--src/corelib/tools/qlocale.cpp1
-rw-r--r--src/corelib/tools/qlocale_data_p.h2
-rw-r--r--src/corelib/tools/qlocale_mac.mm3
-rw-r--r--src/corelib/tools/qlocale_p.h1
-rw-r--r--src/corelib/tools/qlocale_win.cpp78
-rw-r--r--src/corelib/tools/qpodlist_p.h1
-rw-r--r--src/corelib/tools/qpoint.h13
-rw-r--r--src/corelib/tools/qrect.h13
-rw-r--r--src/corelib/tools/qringbuffer.cpp46
-rw-r--r--src/corelib/tools/qringbuffer_p.h9
-rw-r--r--src/corelib/tools/qscopedpointer.cpp42
-rw-r--r--src/corelib/tools/qscopedpointer.h45
-rw-r--r--src/corelib/tools/qscopedpointer_p.h2
-rw-r--r--src/corelib/tools/qsharedpointer.cpp112
-rw-r--r--src/corelib/tools/qsharedpointer.h14
-rw-r--r--src/corelib/tools/qsharedpointer_impl.h116
-rw-r--r--src/corelib/tools/qsimd.cpp29
-rw-r--r--src/corelib/tools/qsimd_p.h63
-rw-r--r--src/corelib/tools/qsize.h13
-rw-r--r--src/corelib/tools/qstring.cpp248
-rw-r--r--src/corelib/tools/qstring.h212
-rw-r--r--src/corelib/tools/qstring_mac.mm83
-rw-r--r--src/corelib/tools/qstringiterator_p.h1
-rw-r--r--src/corelib/tools/qstringlist.h2
-rw-r--r--src/corelib/tools/qtimezoneprivate_data_p.h2
-rw-r--r--src/corelib/tools/qtimezoneprivate_win.cpp6
-rw-r--r--src/corelib/tools/qtools_p.h2
-rw-r--r--src/corelib/tools/qunicodetables_p.h2
-rw-r--r--src/corelib/tools/qunicodetools_p.h1
-rw-r--r--src/corelib/tools/tools.pri32
60 files changed, 1801 insertions, 2446 deletions
diff --git a/src/corelib/tools/qalgorithms.h b/src/corelib/tools/qalgorithms.h
index 4f704d6764..6e472e8b22 100644
--- a/src/corelib/tools/qalgorithms.h
+++ b/src/corelib/tools/qalgorithms.h
@@ -142,15 +142,9 @@ QT_DEPRECATED_X("Use std::count") inline void qCount(const Container &container,
}
#ifdef Q_QDOC
-template <typename T>
-LessThan qLess()
-{
-}
-
-template <typename T>
-LessThan qGreater()
-{
-}
+typedef void* LessThan;
+template <typename T> LessThan qLess();
+template <typename T> LessThan qGreater();
#else
template <typename T>
class QT_DEPRECATED_X("Use std::less") qLess
@@ -522,20 +516,153 @@ QT_DEPRECATED_X("Use std::binary_search") Q_OUTOFLINE_TEMPLATE RandomAccessItera
#endif // QT_DEPRECATED_SINCE(5, 2)
-} //namespace QAlgorithmsPrivate
-
+#ifdef Q_CC_CLANG
+// Clang had a bug where __builtin_ctz/clz/popcount were not marked as constexpr.
+# if (defined __apple_build_version__ && __clang_major__ >= 7) || (Q_CC_CLANG >= 307)
+# define QT_HAS_CONSTEXPR_BUILTINS
+# endif
+#elif defined(Q_CC_MSVC) && !defined(Q_CC_INTEL) && !defined(Q_OS_WINCE) && !defined(Q_PROCESSOR_ARM)
+# define QT_HAS_CONSTEXPR_BUILTINS
+#elif defined(Q_CC_GNU)
+# define QT_HAS_CONSTEXPR_BUILTINS
+#endif
-// Use __builtin_popcount on gcc. Clang claims to be gcc
-// but has a bug where __builtin_popcount is not marked as
-// constexpr.
-#if defined(Q_CC_GNU) && !defined(Q_CC_CLANG)
+#if defined QT_HAS_CONSTEXPR_BUILTINS
+#if defined(Q_CC_GNU) || defined(Q_CC_CLANG)
+# define QT_HAS_BUILTIN_CTZS
+Q_DECL_CONSTEXPR Q_ALWAYS_INLINE uint qt_builtin_ctzs(quint16 v) Q_DECL_NOTHROW
+{
+# if QT_HAS_BUILTIN(__builtin_ctzs) || defined(__BMI__)
+ return __builtin_ctzs(v);
+# else
+ return __builtin_ctz(v);
+# endif
+}
+#define QT_HAS_BUILTIN_CLZS
+Q_DECL_CONSTEXPR Q_ALWAYS_INLINE uint qt_builtin_clzs(quint16 v) Q_DECL_NOTHROW
+{
+# if QT_HAS_BUILTIN(__builtin_clzs) || defined(__BMI__)
+ return __builtin_clzs(v);
+# else
+ return __builtin_clz(v) - 16U;
+# endif
+}
+#define QT_HAS_BUILTIN_CTZ
+Q_DECL_CONSTEXPR Q_ALWAYS_INLINE uint qt_builtin_ctz(quint32 v) Q_DECL_NOTHROW
+{
+ return __builtin_ctz(v);
+}
+#define QT_HAS_BUILTIN_CLZ
+Q_DECL_CONSTEXPR Q_ALWAYS_INLINE uint qt_builtin_clz(quint32 v) Q_DECL_NOTHROW
+{
+ return __builtin_clz(v);
+}
+#define QT_HAS_BUILTIN_CTZLL
+Q_DECL_CONSTEXPR Q_ALWAYS_INLINE uint qt_builtin_ctzll(quint64 v) Q_DECL_NOTHROW
+{
+ return __builtin_ctzll(v);
+}
+#define QT_HAS_BUILTIN_CLZLL
+Q_DECL_CONSTEXPR Q_ALWAYS_INLINE uint qt_builtin_clzll(quint64 v) Q_DECL_NOTHROW
+{
+ return __builtin_clzll(v);
+}
#define QALGORITHMS_USE_BUILTIN_POPCOUNT
-#endif
+Q_DECL_CONSTEXPR Q_ALWAYS_INLINE uint qt_builtin_popcount(quint32 v) Q_DECL_NOTHROW
+{
+ return __builtin_popcount(v);
+}
+Q_DECL_CONSTEXPR Q_ALWAYS_INLINE uint qt_builtin_popcount(quint8 v) Q_DECL_NOTHROW
+{
+ return __builtin_popcount(v);
+}
+Q_DECL_CONSTEXPR Q_ALWAYS_INLINE uint qt_builtin_popcount(quint16 v) Q_DECL_NOTHROW
+{
+ return __builtin_popcount(v);
+}
+#define QALGORITHMS_USE_BUILTIN_POPCOUNTLL
+Q_DECL_CONSTEXPR Q_ALWAYS_INLINE uint qt_builtin_popcountll(quint64 v) Q_DECL_NOTHROW
+{
+ return __builtin_popcountll(v);
+}
+#elif defined(Q_CC_MSVC) && !defined(Q_OS_WINCE) && !defined(Q_PROCESSOR_ARM)
+#define QT_HAS_BUILTIN_CTZ
+Q_DECL_CONSTEXPR Q_ALWAYS_INLINE unsigned long qt_builtin_ctz(quint32 val)
+{
+ unsigned long result;
+ _BitScanForward(&result, val);
+ return result;
+}
+#define QT_HAS_BUILTIN_CLZ
+Q_DECL_CONSTEXPR Q_ALWAYS_INLINE unsigned long qt_builtin_clz(quint32 val)
+{
+ unsigned long result;
+ _BitScanReverse(&result, val);
+ // Now Invert the result: clz will count *down* from the msb to the lsb, so the msb index is 31
+ // and the lsb index is 0. The result for the index when counting up: msb index is 0 (because it
+ // starts there), and the lsb index is 31.
+ result ^= sizeof(quint32) * 8 - 1;
+ return result;
+}
+#if Q_PROCESSOR_WORDSIZE == 8
+// These are only defined for 64bit builds.
+#define QT_HAS_BUILTIN_CTZLL
+Q_DECL_CONSTEXPR Q_ALWAYS_INLINE unsigned long qt_builtin_ctzll(quint64 val)
+{
+ unsigned long result;
+ _BitScanForward64(&result, val);
+ return result;
+}
+// MSVC calls it _BitScanReverse and returns the carry flag, which we don't need
+#define QT_HAS_BUILTIN_CLZLL
+Q_DECL_CONSTEXPR Q_ALWAYS_INLINE unsigned long qt_builtin_clzll(quint64 val)
+{
+ unsigned long result;
+ _BitScanReverse64(&result, val);
+ // see qt_builtin_clz
+ result ^= sizeof(quint64) * 8 - 1;
+ return result;
+}
+#endif // MSVC 64bit
+# define QT_HAS_BUILTIN_CTZS
+Q_DECL_CONSTEXPR Q_ALWAYS_INLINE uint qt_builtin_ctzs(quint16 v) Q_DECL_NOTHROW
+{
+ return qt_builtin_ctz(v);
+}
+#define QT_HAS_BUILTIN_CLZS
+Q_DECL_CONSTEXPR Q_ALWAYS_INLINE uint qt_builtin_clzs(quint16 v) Q_DECL_NOTHROW
+{
+ return qt_builtin_clz(v) - 16U;
+}
+#define QALGORITHMS_USE_BUILTIN_POPCOUNT
+Q_DECL_CONSTEXPR Q_ALWAYS_INLINE uint qt_builtin_popcount(quint32 v) Q_DECL_NOTHROW
+{
+ return __popcnt(v);
+}
+Q_DECL_CONSTEXPR Q_ALWAYS_INLINE uint qt_builtin_popcount(quint8 v) Q_DECL_NOTHROW
+{
+ return __popcnt16(v);
+}
+Q_DECL_CONSTEXPR Q_ALWAYS_INLINE uint qt_builtin_popcount(quint16 v) Q_DECL_NOTHROW
+{
+ return __popcnt16(v);
+}
+#if Q_PROCESSOR_WORDSIZE == 8
+#define QALGORITHMS_USE_BUILTIN_POPCOUNTLL
+Q_DECL_CONSTEXPR Q_ALWAYS_INLINE uint qt_builtin_popcountll(quint64 v) Q_DECL_NOTHROW
+{
+ return __popcnt64(v);
+}
+#endif // MSVC 64bit
+#endif // MSVC
+#endif // QT_HAS_CONSTEXPR_BUILTINS
+
+} //namespace QAlgorithmsPrivate
Q_DECL_CONST_FUNCTION Q_DECL_CONSTEXPR inline uint qPopulationCount(quint32 v) Q_DECL_NOTHROW
{
#ifdef QALGORITHMS_USE_BUILTIN_POPCOUNT
- return __builtin_popcount(v);
+ return QAlgorithmsPrivate::qt_builtin_popcount(v);
#else
// See http://graphics.stanford.edu/~seander/bithacks.html#CountBitsSetParallel
return
@@ -548,7 +675,7 @@ Q_DECL_CONST_FUNCTION Q_DECL_CONSTEXPR inline uint qPopulationCount(quint32 v) Q
Q_DECL_CONST_FUNCTION Q_DECL_CONSTEXPR inline uint qPopulationCount(quint8 v) Q_DECL_NOTHROW
{
#ifdef QALGORITHMS_USE_BUILTIN_POPCOUNT
- return __builtin_popcount(v);
+ return QAlgorithmsPrivate::qt_builtin_popcount(v);
#else
return
(((v ) & 0xfff) * Q_UINT64_C(0x1001001001001) & Q_UINT64_C(0x84210842108421)) % 0x1f;
@@ -558,7 +685,7 @@ Q_DECL_CONST_FUNCTION Q_DECL_CONSTEXPR inline uint qPopulationCount(quint8 v) Q_
Q_DECL_CONST_FUNCTION Q_DECL_CONSTEXPR inline uint qPopulationCount(quint16 v) Q_DECL_NOTHROW
{
#ifdef QALGORITHMS_USE_BUILTIN_POPCOUNT
- return __builtin_popcount(v);
+ return QAlgorithmsPrivate::qt_builtin_popcount(v);
#else
return
(((v ) & 0xfff) * Q_UINT64_C(0x1001001001001) & Q_UINT64_C(0x84210842108421)) % 0x1f +
@@ -568,8 +695,8 @@ Q_DECL_CONST_FUNCTION Q_DECL_CONSTEXPR inline uint qPopulationCount(quint16 v) Q
Q_DECL_CONST_FUNCTION Q_DECL_CONSTEXPR inline uint qPopulationCount(quint64 v) Q_DECL_NOTHROW
{
-#ifdef QALGORITHMS_USE_BUILTIN_POPCOUNT
- return __builtin_popcountll(v);
+#ifdef QALGORITHMS_USE_BUILTIN_POPCOUNTLL
+ return QAlgorithmsPrivate::qt_builtin_popcountll(v);
#else
return
(((v ) & 0xfff) * Q_UINT64_C(0x1001001001001) & Q_UINT64_C(0x84210842108421)) % 0x1f +
@@ -592,8 +719,8 @@ Q_DECL_CONST_FUNCTION Q_DECL_CONSTEXPR inline uint qPopulationCount(long unsigne
Q_DECL_RELAXED_CONSTEXPR inline uint qCountTrailingZeroBits(quint32 v) Q_DECL_NOTHROW
{
-#if defined(Q_CC_GNU)
- return v ? __builtin_ctz(v) : 32U;
+#if defined(QT_HAS_BUILTIN_CTZ)
+ return v ? QAlgorithmsPrivate::qt_builtin_ctz(v) : 32U;
#else
// see http://graphics.stanford.edu/~seander/bithacks.html#ZerosOnRightParallel
unsigned int c = 32; // c will be the number of zero bits on the right
@@ -610,8 +737,8 @@ Q_DECL_RELAXED_CONSTEXPR inline uint qCountTrailingZeroBits(quint32 v) Q_DECL_NO
Q_DECL_RELAXED_CONSTEXPR inline uint qCountTrailingZeroBits(quint8 v) Q_DECL_NOTHROW
{
-#if defined(Q_CC_GNU)
- return v ? __builtin_ctz(v) : 8U;
+#if defined(QT_HAS_BUILTIN_CTZ)
+ return v ? QAlgorithmsPrivate::qt_builtin_ctz(v) : 8U;
#else
unsigned int c = 8; // c will be the number of zero bits on the right
v &= -signed(v);
@@ -625,12 +752,8 @@ Q_DECL_RELAXED_CONSTEXPR inline uint qCountTrailingZeroBits(quint8 v) Q_DECL_NOT
Q_DECL_RELAXED_CONSTEXPR inline uint qCountTrailingZeroBits(quint16 v) Q_DECL_NOTHROW
{
-#if defined(Q_CC_GNU)
-# if QT_HAS_BUILTIN(__builtin_ctzs) || (defined(__LZCNT__) && defined(__BMI__))
- return v ? __builtin_ctzs(v) : 16U;
-# else
- return v ? __builtin_ctz(v) : 16U;
-# endif
+#if defined(QT_HAS_BUILTIN_CTZS)
+ return v ? QAlgorithmsPrivate::qt_builtin_ctzs(v) : 16U;
#else
unsigned int c = 16; // c will be the number of zero bits on the right
v &= -signed(v);
@@ -645,8 +768,8 @@ Q_DECL_RELAXED_CONSTEXPR inline uint qCountTrailingZeroBits(quint16 v) Q_DECL_NO
Q_DECL_RELAXED_CONSTEXPR inline uint qCountTrailingZeroBits(quint64 v) Q_DECL_NOTHROW
{
-#if defined(Q_CC_GNU)
- return v ? __builtin_ctzll(v) : 64;
+#if defined(QT_HAS_BUILTIN_CTZLL)
+ return v ? QAlgorithmsPrivate::qt_builtin_ctzll(v) : 64;
#else
quint32 x = static_cast<quint32>(v);
return x ? qCountTrailingZeroBits(x)
@@ -661,8 +784,8 @@ Q_DECL_RELAXED_CONSTEXPR inline uint qCountTrailingZeroBits(unsigned long v) Q_D
Q_DECL_RELAXED_CONSTEXPR inline uint qCountLeadingZeroBits(quint32 v) Q_DECL_NOTHROW
{
-#if defined(Q_CC_GNU)
- return v ? __builtin_clz(v) : 32U;
+#if defined(QT_HAS_BUILTIN_CLZ)
+ return v ? QAlgorithmsPrivate::qt_builtin_clz(v) : 32U;
#else
// Hacker's Delight, 2nd ed. Fig 5-16, p. 102
v = v | (v >> 1);
@@ -676,8 +799,8 @@ Q_DECL_RELAXED_CONSTEXPR inline uint qCountLeadingZeroBits(quint32 v) Q_DECL_NOT
Q_DECL_RELAXED_CONSTEXPR inline uint qCountLeadingZeroBits(quint8 v) Q_DECL_NOTHROW
{
-#if defined(Q_CC_GNU)
- return v ? __builtin_clz(v)-24U : 8U;
+#if defined(QT_HAS_BUILTIN_CLZ)
+ return v ? QAlgorithmsPrivate::qt_builtin_clz(v)-24U : 8U;
#else
v = v | (v >> 1);
v = v | (v >> 2);
@@ -688,12 +811,8 @@ Q_DECL_RELAXED_CONSTEXPR inline uint qCountLeadingZeroBits(quint8 v) Q_DECL_NOTH
Q_DECL_RELAXED_CONSTEXPR inline uint qCountLeadingZeroBits(quint16 v) Q_DECL_NOTHROW
{
-#if defined(Q_CC_GNU)
-# if QT_HAS_BUILTIN(__builtin_clzs) || (defined(__LZCNT__) && defined(__BMI__))
- return v ? __builtin_clzs(v) : 16U;
-# else
- return v ? __builtin_clz(v)-16U : 16U;
-# endif
+#if defined(QT_HAS_BUILTIN_CLZS)
+ return v ? QAlgorithmsPrivate::qt_builtin_clzs(v) : 16U;
#else
v = v | (v >> 1);
v = v | (v >> 2);
@@ -705,8 +824,8 @@ Q_DECL_RELAXED_CONSTEXPR inline uint qCountLeadingZeroBits(quint16 v) Q_DECL_NOT
Q_DECL_RELAXED_CONSTEXPR inline uint qCountLeadingZeroBits(quint64 v) Q_DECL_NOTHROW
{
-#if defined(Q_CC_GNU)
- return v ? __builtin_clzll(v) : 64U;
+#if defined(QT_HAS_BUILTIN_CLZLL)
+ return v ? QAlgorithmsPrivate::qt_builtin_clzll(v) : 64U;
#else
v = v | (v >> 1);
v = v | (v >> 2);
diff --git a/src/corelib/tools/qbytearray.cpp b/src/corelib/tools/qbytearray.cpp
index c9d6f4e411..266c2e9b57 100644
--- a/src/corelib/tools/qbytearray.cpp
+++ b/src/corelib/tools/qbytearray.cpp
@@ -4467,91 +4467,6 @@ QByteArray QByteArray::fromPercentEncoding(const QByteArray &input, char percent
\sa fromStdString(), QString::toStdString()
*/
-/*! \fn QByteArray QByteArray::fromCFData(CFDataRef data)
- \since 5.3
-
- Constructs a new QByteArray containing a copy of the CFData \a data.
-
- \sa fromRawCFData(), fromRawData(), toRawCFData(), toCFData()
-*/
-
-/*! \fn QByteArray QByteArray::fromRawCFData(CFDataRef data)
- \since 5.3
-
- Constructs a QByteArray that uses the bytes of the CFData \a data.
-
- The \a data's bytes are not copied.
-
- The caller guarantees that the CFData will not be deleted
- or modified as long as this QByteArray object exists.
-
- \sa fromCFData(), fromRawData(), toRawCFData(), toCFData()
-*/
-
-/*! \fn CFDataRef QByteArray::toCFData() const
- \since 5.3
-
- Creates a CFData from a QByteArray. The caller owns the CFData object
- and is responsible for releasing it.
-
- \sa toRawCFData(), fromCFData(), fromRawCFData(), fromRawData()
-*/
-
-/*! \fn CFDataRef QByteArray::toRawCFData() const
- \since 5.3
-
- Constructs a CFData that uses the bytes of the QByteArray.
-
- The QByteArray's bytes are not copied.
-
- The caller guarantees that the QByteArray will not be deleted
- or modified as long as this CFData object exists.
-
- \sa toCFData(), fromRawCFData(), fromCFData(), fromRawData()
-*/
-
-/*! \fn QByteArray QByteArray::fromNSData(const NSData *data)
- \since 5.3
-
- Constructs a new QByteArray containing a copy of the NSData \a data.
-
- \sa fromRawNSData(), fromRawData(), toNSData(), toRawNSData()
-*/
-
-/*! \fn QByteArray QByteArray::fromRawNSData(const NSData *data)
- \since 5.3
-
- Constructs a QByteArray that uses the bytes of the NSData \a data.
-
- The \a data's bytes are not copied.
-
- The caller guarantees that the NSData will not be deleted
- or modified as long as this QByteArray object exists.
-
- \sa fromNSData(), fromRawData(), toRawNSData(), toNSData()
-*/
-
-/*! \fn NSData QByteArray::toNSData() const
- \since 5.3
-
- Creates a NSData from a QByteArray. The NSData object is autoreleased.
-
- \sa fromNSData(), fromRawNSData(), fromRawData(), toRawNSData()
-*/
-
-/*! \fn NSData QByteArray::toRawNSData() const
- \since 5.3
-
- Constructs a NSData that uses the bytes of the QByteArray.
-
- The QByteArray's bytes are not copied.
-
- The caller guarantees that the QByteArray will not be deleted
- or modified as long as this NSData object exists.
-
- \sa fromRawNSData(), fromNSData(), fromRawData(), toNSData()
-*/
-
static inline bool q_strchr(const char str[], char chr)
{
if (!str) return false;
diff --git a/src/corelib/tools/qbytearray.h b/src/corelib/tools/qbytearray.h
index d334bb43c5..477402d6de 100644
--- a/src/corelib/tools/qbytearray.h
+++ b/src/corelib/tools/qbytearray.h
@@ -56,11 +56,9 @@
#error qbytearray.h must be included before any header file that defines truncate
#endif
-#ifdef Q_OS_MAC
+#if defined(Q_OS_DARWIN) || defined(Q_QDOC)
Q_FORWARD_DECLARE_CF_TYPE(CFData);
-# ifdef __OBJC__
Q_FORWARD_DECLARE_OBJC_CLASS(NSData);
-# endif
#endif
QT_BEGIN_NAMESPACE
@@ -384,17 +382,15 @@ public:
static QByteArray fromHex(const QByteArray &hexEncoded) Q_REQUIRED_RESULT;
static QByteArray fromPercentEncoding(const QByteArray &pctEncoded, char percent = '%') Q_REQUIRED_RESULT;
-#if defined(Q_OS_MAC) || defined(Q_QDOC)
+#if defined(Q_OS_DARWIN) || defined(Q_QDOC)
static QByteArray fromCFData(CFDataRef data);
static QByteArray fromRawCFData(CFDataRef data);
CFDataRef toCFData() const Q_DECL_CF_RETURNS_RETAINED;
CFDataRef toRawCFData() const Q_DECL_CF_RETURNS_RETAINED;
-# if defined(__OBJC__) || defined(Q_QDOC)
static QByteArray fromNSData(const NSData *data);
static QByteArray fromRawNSData(const NSData *data);
NSData *toNSData() const Q_DECL_NS_RETURNS_AUTORELEASED;
NSData *toRawNSData() const Q_DECL_NS_RETURNS_AUTORELEASED;
-# endif
#endif
typedef char *iterator;
diff --git a/src/corelib/tools/qbytearray_mac.mm b/src/corelib/tools/qbytearray_mac.mm
deleted file mode 100644
index 9386a966f0..0000000000
--- a/src/corelib/tools/qbytearray_mac.mm
+++ /dev/null
@@ -1,99 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2014 Samuel Gaist <samuel.gaist@edeltech.ch>
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtCore module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include "qbytearray.h"
-
-#import <Foundation/Foundation.h>
-
-QT_BEGIN_NAMESPACE
-
-QByteArray QByteArray::fromCFData(CFDataRef data)
-{
- if (!data)
- return QByteArray();
-
- return QByteArray(reinterpret_cast<const char *>(CFDataGetBytePtr(data)), CFDataGetLength(data));
-}
-
-QByteArray QByteArray::fromRawCFData(CFDataRef data)
-{
- if (!data)
- return QByteArray();
-
- return QByteArray::fromRawData(reinterpret_cast<const char *>(CFDataGetBytePtr(data)), CFDataGetLength(data));
-}
-
-CFDataRef QByteArray::toCFData() const
-{
- return CFDataCreate(kCFAllocatorDefault, reinterpret_cast<const UInt8 *>(data()), length());
-}
-
-CFDataRef QByteArray::toRawCFData() const
-{
- return CFDataCreateWithBytesNoCopy(kCFAllocatorDefault, reinterpret_cast<const UInt8 *>(data()),
- length(), kCFAllocatorNull);
-}
-
-QByteArray QByteArray::fromNSData(const NSData *data)
-{
- if (!data)
- return QByteArray();
- return QByteArray(reinterpret_cast<const char *>([data bytes]), [data length]);
-}
-
-QByteArray QByteArray::fromRawNSData(const NSData *data)
-{
- if (!data)
- return QByteArray();
- return QByteArray::fromRawData(reinterpret_cast<const char *>([data bytes]), [data length]);
-}
-
-NSData *QByteArray::toNSData() const
-{
- return [NSData dataWithBytes:constData() length:size()];
-}
-
-NSData *QByteArray::toRawNSData() const
-{
- // const_cast is fine here because NSData is immutable thus will never modify bytes we're giving it
- return [NSData dataWithBytesNoCopy:const_cast<char *>(constData()) length:size() freeWhenDone:NO];
-}
-
-QT_END_NAMESPACE
diff --git a/src/corelib/tools/qbytearraylist.h b/src/corelib/tools/qbytearraylist.h
index bc8b08b380..501bb2e0d5 100644
--- a/src/corelib/tools/qbytearraylist.h
+++ b/src/corelib/tools/qbytearraylist.h
@@ -50,11 +50,13 @@ QT_BEGIN_NAMESPACE
typedef QListIterator<QByteArray> QByteArrayListIterator;
typedef QMutableListIterator<QByteArray> QMutableByteArrayListIterator;
+#ifndef Q_QDOC
typedef QList<QByteArray> QByteArrayList;
namespace QtPrivate {
QByteArray Q_CORE_EXPORT QByteArrayList_join(const QByteArrayList *that, const char *separator, int separatorLength);
}
+#endif
#ifdef Q_QDOC
class QByteArrayList : public QList<QByteArray>
diff --git a/src/corelib/tools/qbytedata_p.h b/src/corelib/tools/qbytedata_p.h
index b275158597..8331be112d 100644
--- a/src/corelib/tools/qbytedata_p.h
+++ b/src/corelib/tools/qbytedata_p.h
@@ -51,6 +51,7 @@
// We mean it.
//
+#include <QtCore/private/qglobal_p.h>
#include <qbytearray.h>
QT_BEGIN_NAMESPACE
diff --git a/src/corelib/tools/qchar.h b/src/corelib/tools/qchar.h
index f01fbc109c..a83e5e6f98 100644
--- a/src/corelib/tools/qchar.h
+++ b/src/corelib/tools/qchar.h
@@ -578,6 +578,18 @@ Q_DECL_CONSTEXPR inline bool operator>=(QChar c1, QChar c2) Q_DECL_NOTHROW { ret
Q_DECL_CONSTEXPR inline bool operator> (QChar c1, QChar c2) Q_DECL_NOTHROW { return operator< (c2, c1); }
Q_DECL_CONSTEXPR inline bool operator<=(QChar c1, QChar c2) Q_DECL_NOTHROW { return !operator< (c2, c1); }
+// disambiguate QChar == int (but only that, so constrain template to exactly 'int'):
+template <typename T>
+Q_DECL_DEPRECATED_X("don't compare ints to QChars, compare them to QChar::unicode() instead")
+Q_DECL_CONSTEXPR inline
+typename std::enable_if<std::is_same<typename std::remove_cv<T>::type, int>::value, bool>::type
+operator==(QChar lhs, T rhs) Q_DECL_NOEXCEPT { return lhs == QChar(rhs); }
+template <typename T>
+Q_DECL_DEPRECATED_X("don't compare ints to QChars, compare them to QChar::unicode() instead")
+Q_DECL_CONSTEXPR inline
+typename std::enable_if<std::is_same<typename std::remove_cv<T>::type, int>::value, bool>::type
+operator!=(QChar lhs, T rhs) Q_DECL_NOEXCEPT { return lhs != QChar(rhs); }
+
#ifndef QT_NO_DATASTREAM
Q_CORE_EXPORT QDataStream &operator<<(QDataStream &, QChar);
Q_CORE_EXPORT QDataStream &operator>>(QDataStream &, QChar &);
diff --git a/src/corelib/tools/qcollator_p.h b/src/corelib/tools/qcollator_p.h
index a056fcc4af..fbbce00676 100644
--- a/src/corelib/tools/qcollator_p.h
+++ b/src/corelib/tools/qcollator_p.h
@@ -52,6 +52,7 @@
// We mean it.
//
+#include <QtCore/private/qglobal_p.h>
#include "qcollator.h"
#include <QVector>
#ifdef QT_USE_ICU
diff --git a/src/corelib/tools/qcommandlineoption.cpp b/src/corelib/tools/qcommandlineoption.cpp
index 751e18c44e..c2b86014ba 100644
--- a/src/corelib/tools/qcommandlineoption.cpp
+++ b/src/corelib/tools/qcommandlineoption.cpp
@@ -49,14 +49,12 @@ class QCommandLineOptionPrivate : public QSharedData
public:
Q_NEVER_INLINE
explicit QCommandLineOptionPrivate(const QString &name)
- : names(removeInvalidNames(QStringList(name))),
- hidden(false)
+ : names(removeInvalidNames(QStringList(name)))
{ }
Q_NEVER_INLINE
explicit QCommandLineOptionPrivate(const QStringList &names)
- : names(removeInvalidNames(names)),
- hidden(false)
+ : names(removeInvalidNames(names))
{ }
static QStringList removeInvalidNames(QStringList nameList);
@@ -74,8 +72,7 @@ public:
//! The list of default values used for this option.
QStringList defaultValues;
- //! Show or hide in --help
- bool hidden;
+ QCommandLineOption::Flags flags;
};
/*!
@@ -394,6 +391,7 @@ QStringList QCommandLineOption::defaultValues() const
return d->defaultValues;
}
+#if QT_DEPRECATED_SINCE(5, 8)
/*!
Sets whether to hide this option in the user-visible help output.
@@ -401,11 +399,12 @@ QStringList QCommandLineOption::defaultValues() const
a particular option makes it internal, i.e. not listed in the help output.
\since 5.6
+ \obsolete Use setFlags(QCommandLineOption::HiddenFromHelp), QCommandLineOption::HiddenFromHelp
\sa isHidden
*/
void QCommandLineOption::setHidden(bool hide)
{
- d->hidden = hide;
+ d->flags.setFlag(HiddenFromHelp, hide);
}
/*!
@@ -413,11 +412,52 @@ void QCommandLineOption::setHidden(bool hide)
false if the option is listed.
\since 5.6
- \sa setHidden()
+ \obsolete Use flags() & QCommandLineOption::HiddenFromHelp
+ \sa setHidden(), QCommandLineOption::HiddenFromHelp
*/
bool QCommandLineOption::isHidden() const
{
- return d->hidden;
+ return d->flags & HiddenFromHelp;
}
+#endif
+
+/*!
+ Returns a set of flags that affect this command-line option.
+
+ \since 5.8
+ \sa setFlags(), QCommandLineOption::Flags
+ */
+QCommandLineOption::Flags QCommandLineOption::flags() const
+{
+ return d->flags;
+}
+
+/*!
+ Set the set of flags that affect this command-line option to \a flags.
+
+ \since 5.8
+ \sa flags(), QCommandLineOption::Flags
+ */
+void QCommandLineOption::setFlags(Flags flags)
+{
+ d->flags = flags;
+}
+
+/*!
+ \enum QCommandLineOption::Flag
+
+ \value HiddenFromHelp Hide this option in the user-visible help output. All
+ options are visible by default. Setting this flag for a particular
+ option makes it internal, i.e. not listed in the help output.
+
+ \value ShortOptionStyle The option will always be understood as a short
+ option, regardless of what was set by
+ QCommandLineParser::setSingleDashWordOptionMode.
+ This allows flags such as \c{-DDEFINE=VALUE} or \c{-I/include/path} to be
+ interpreted as short flags even when the parser is in
+ QCommandLineParser::ParseAsLongOptions mode.
+
+ \sa QCommandLineOption::setFlags(), QCommandLineOption::flags()
+*/
QT_END_NAMESPACE
diff --git a/src/corelib/tools/qcommandlineoption.h b/src/corelib/tools/qcommandlineoption.h
index a7747f9fb2..6ebaab3d48 100644
--- a/src/corelib/tools/qcommandlineoption.h
+++ b/src/corelib/tools/qcommandlineoption.h
@@ -50,6 +50,12 @@ class QCommandLineOptionPrivate;
class Q_CORE_EXPORT QCommandLineOption
{
public:
+ enum Flag {
+ HiddenFromHelp = 0x1,
+ ShortOptionStyle = 0x2
+ };
+ Q_DECLARE_FLAGS(Flags, Flag)
+
explicit QCommandLineOption(const QString &name);
explicit QCommandLineOption(const QStringList &names);
/*implicit*/ QCommandLineOption(const QString &name, const QString &description,
@@ -82,14 +88,24 @@ public:
void setDefaultValues(const QStringList &defaultValues);
QStringList defaultValues() const;
+ Flags flags() const;
+ void setFlags(Flags aflags);
+
+#if QT_DEPRECATED_SINCE(5, 8)
+ QT_DEPRECATED_X("Use setFlags() with HiddenFromHelp)")
void setHidden(bool hidden);
+ QT_DEPRECATED_X("Use flags() and HiddenFromHelp")
bool isHidden() const;
+#endif
+
private:
QSharedDataPointer<QCommandLineOptionPrivate> d;
};
Q_DECLARE_SHARED(QCommandLineOption)
+Q_DECLARE_OPERATORS_FOR_FLAGS(QCommandLineOption::Flags)
+
QT_END_NAMESPACE
diff --git a/src/corelib/tools/qcommandlineparser.cpp b/src/corelib/tools/qcommandlineparser.cpp
index a7ab8b9e70..2450484ce9 100644
--- a/src/corelib/tools/qcommandlineparser.cpp
+++ b/src/corelib/tools/qcommandlineparser.cpp
@@ -44,7 +44,7 @@
#include <qhash.h>
#include <qvector.h>
#include <qdebug.h>
-#if defined(Q_OS_WIN) && !defined(QT_BOOTSTRAPPED) && !defined(Q_OS_WINCE) && !defined(Q_OS_WINRT)
+#if defined(Q_OS_WIN) && !defined(QT_BOOTSTRAPPED) && !defined(Q_OS_WINRT)
# include <qt_windows.h>
#endif
#include <stdio.h>
@@ -295,7 +295,9 @@ QCommandLineParser::~QCommandLineParser()
i.e. as the long option named \c{abc}. This is how Qt's own tools
(uic, rcc...) have always been parsing arguments. This mode should be
used for preserving compatibility in applications that were parsing
- arguments in such a way.
+ arguments in such a way. There is an exception if the \c{a} option has the
+ QCommandLineOption::ShortOptionStyle flag set, in which case it is still
+ interpreted as \c{-a bc}.
\sa setSingleDashWordOptionMode()
*/
@@ -530,7 +532,7 @@ QString QCommandLineParser::errorText() const
enum MessageType { UsageMessage, ErrorMessage };
-#if defined(Q_OS_WIN) && !defined(QT_BOOTSTRAPPED) && !defined(Q_OS_WINCE) && !defined(Q_OS_WINRT)
+#if defined(Q_OS_WIN) && !defined(QT_BOOTSTRAPPED) && !defined(Q_OS_WINRT)
// Return whether to use a message box. Use handles if a console can be obtained
// or we are run with redirected handles (for example, by QProcess).
static inline bool displayMessageBox()
@@ -552,7 +554,7 @@ static void showParserMessage(const QString &message, MessageType type)
else
qCritical(qPrintable(message));
return;
-#elif defined(Q_OS_WIN) && !defined(QT_BOOTSTRAPPED) && !defined(Q_OS_WINCE)
+#elif defined(Q_OS_WIN) && !defined(QT_BOOTSTRAPPED)
if (displayMessageBox()) {
const UINT flags = MB_OK | MB_TOPMOST | MB_SETFOREGROUND
| (type == UsageMessage ? MB_ICONINFORMATION : MB_ICONERROR);
@@ -565,7 +567,7 @@ static void showParserMessage(const QString &message, MessageType type)
reinterpret_cast<const wchar_t *>(title.utf16()), flags);
return;
}
-#endif // Q_OS_WIN && !QT_BOOTSTRAPPED && !Q_OS_WINCE
+#endif // Q_OS_WIN && !QT_BOOTSTRAPPED
fputs(qPrintable(message), type == UsageMessage ? stdout : stderr);
}
@@ -762,6 +764,18 @@ bool QCommandLineParserPrivate::parse(const QStringList &args)
}
case QCommandLineParser::ParseAsLongOptions:
{
+ if (argument.size() > 2) {
+ const QString possibleShortOptionStyleName = argument.mid(1, 1);
+ const auto shortOptionIt = nameHash.constFind(possibleShortOptionStyleName);
+ if (shortOptionIt != nameHash.constEnd()) {
+ const auto &arg = commandLineOptionList.at(*shortOptionIt);
+ if (arg.flags() & QCommandLineOption::ShortOptionStyle) {
+ registerFoundOption(possibleShortOptionStyleName);
+ optionValuesHash[*shortOptionIt].append(argument.mid(2));
+ break;
+ }
+ }
+ }
const QString optionName = argument.mid(1).section(assignChar, 0, 0);
if (registerFoundOption(optionName)) {
if (!parseOptionValue(optionName, argument, &argumentIterator, args.end()))
@@ -1098,7 +1112,7 @@ QString QCommandLineParserPrivate::helpText() const
optionNameList.reserve(commandLineOptionList.size());
int longestOptionNameString = 0;
for (const QCommandLineOption &option : commandLineOptionList) {
- if (option.isHidden())
+ if (option.flags() & QCommandLineOption::HiddenFromHelp)
continue;
const QStringList optionNames = option.names();
QString optionNamesString;
@@ -1117,7 +1131,7 @@ QString QCommandLineParserPrivate::helpText() const
++longestOptionNameString;
auto optionNameIterator = optionNameList.cbegin();
for (const QCommandLineOption &option : commandLineOptionList) {
- if (option.isHidden())
+ if (option.flags() & QCommandLineOption::HiddenFromHelp)
continue;
text += wrapText(*optionNameIterator, longestOptionNameString, option.description());
++optionNameIterator;
diff --git a/src/corelib/tools/qcryptographichash.h b/src/corelib/tools/qcryptographichash.h
index a19c734768..0f17baa036 100644
--- a/src/corelib/tools/qcryptographichash.h
+++ b/src/corelib/tools/qcryptographichash.h
@@ -42,6 +42,7 @@
#define QCRYPTOGRAPHICHASH_H
#include <QtCore/qbytearray.h>
+#include <QtCore/qobjectdefs.h>
QT_BEGIN_NAMESPACE
@@ -51,6 +52,7 @@ class QIODevice;
class Q_CORE_EXPORT QCryptographicHash
{
+ Q_GADGET
public:
enum Algorithm {
#ifndef QT_CRYPTOGRAPHICHASH_ONLY_SHA1
@@ -69,6 +71,7 @@ public:
Sha3_512
#endif
};
+ Q_ENUM(Algorithm)
explicit QCryptographicHash(Algorithm method);
~QCryptographicHash();
diff --git a/src/corelib/tools/qdatetime.cpp b/src/corelib/tools/qdatetime.cpp
index a8010af74c..ee5ee5c362 100644
--- a/src/corelib/tools/qdatetime.cpp
+++ b/src/corelib/tools/qdatetime.cpp
@@ -57,9 +57,6 @@
#include <time.h>
#ifdef Q_OS_WIN
# include <qt_windows.h>
-# ifdef Q_OS_WINCE
-# include "qfunctions_wince.h"
-# endif
# ifdef Q_OS_WINRT
# include "qfunctions_winrt.h"
# endif
@@ -71,8 +68,6 @@
QT_BEGIN_NAMESPACE
-Q_GLOBAL_STATIC_WITH_ARGS(QSharedDataPointer<QDateTimePrivate>, defaultDateTimePrivate, (new QDateTimePrivate()))
-
/*****************************************************************************
Date/Time Constants
*****************************************************************************/
@@ -1685,9 +1680,6 @@ QString QTime::toString(const QString& format) const
bool QTime::setHMS(int h, int m, int s, int ms)
{
-#if defined(Q_OS_WINCE)
- startTick = NullTime;
-#endif
if (!isValid(h,m,s,ms)) {
mds = NullTime; // make this invalid
return false;
@@ -1767,10 +1759,6 @@ QTime QTime::addMSecs(int ms) const
t.mds = (ds() + ms) % MSECS_PER_DAY;
}
}
-#if defined(Q_OS_WINCE)
- if (startTick > NullTime)
- t.startTick = (startTick + ms) % MSECS_PER_DAY;
-#endif
return t;
}
@@ -1792,13 +1780,7 @@ int QTime::msecsTo(const QTime &t) const
{
if (!isValid() || !t.isValid())
return 0;
-#if defined(Q_OS_WINCE)
- // GetLocalTime() for Windows CE has no milliseconds resolution
- if (t.startTick > NullTime && startTick > NullTime)
- return t.startTick - startTick;
- else
-#endif
- return t.ds() - ds();
+ return t.ds() - ds();
}
@@ -2137,13 +2119,14 @@ int QTime::elapsed() const
QDateTime static helper functions
*****************************************************************************/
+// get the types from QDateTime (through QDateTimePrivate)
+typedef QDateTimePrivate::QDateTimeShortData ShortData;
+typedef QDateTimePrivate::QDateTimeData QDateTimeData;
+
// Calls the platform variant of tzset
static void qt_tzset()
{
-#if defined(Q_OS_WINCE)
- // WinCE doesn't use tzset
- return;
-#elif defined(Q_OS_WIN)
+#if defined(Q_OS_WIN)
_tzset();
#else
tzset();
@@ -2157,12 +2140,7 @@ static void qt_tzset()
// Relies on tzset, mktime, or localtime having been called to populate timezone
static int qt_timezone()
{
-#if defined(Q_OS_WINCE)
- TIME_ZONE_INFORMATION tzi;
- GetTimeZoneInformation(&tzi);
- // Expressed in minutes, convert to seconds
- return (tzi.Bias + tzi.StandardBias) * 60;
-#elif defined(_MSC_VER) && _MSC_VER >= 1400
+#if defined(_MSC_VER)
long offset;
_get_timezone(&offset);
return offset;
@@ -2191,16 +2169,6 @@ static int qt_timezone()
// Returns the tzname, assume tzset has been called already
static QString qt_tzname(QDateTimePrivate::DaylightStatus daylightStatus)
{
-#if defined(Q_OS_WINCE)
- TIME_ZONE_INFORMATION tzi;
- DWORD res = GetTimeZoneInformation(&tzi);
- if (res == TIME_ZONE_ID_UNKNOWN)
- return QString();
- else if (daylightStatus == QDateTimePrivate::DaylightTime)
- return QString::fromWCharArray(tzi.DaylightName);
- else
- return QString::fromWCharArray(tzi.StandardName);
-#else
int isDst = (daylightStatus == QDateTimePrivate::DaylightTime) ? 1 : 0;
#if defined(_MSC_VER) && _MSC_VER >= 1400
size_t s = 0;
@@ -2211,7 +2179,6 @@ static QString qt_tzname(QDateTimePrivate::DaylightStatus daylightStatus)
#else
return QString::fromLocal8Bit(tzname[isDst]);
#endif // Q_OS_WIN
-#endif // Q_OS_WINCE
}
// Calls the platform variant of mktime for the given date, time and daylightStatus,
@@ -2226,48 +2193,6 @@ static qint64 qt_mktime(QDate *date, QTime *time, QDateTimePrivate::DaylightStat
int yy, mm, dd;
date->getDate(&yy, &mm, &dd);
-#if defined(Q_OS_WINCE)
- // WinCE doesn't provide standard C library time functions
- SYSTEMTIME st;
- memset(&st, 0, sizeof(SYSTEMTIME));
- st.wSecond = time->second();
- st.wMinute = time->minute();
- st.wHour = time->hour();
- st.wDay = dd;
- st.wMonth = mm;
- st.wYear = yy;
- FILETIME lft;
- bool valid = SystemTimeToFileTime(&st, &lft);
- FILETIME ft;
- if (valid)
- valid = LocalFileTimeToFileTime(&lft, &ft);
- const time_t secsSinceEpoch = ftToTime_t(ft);
- const time_t localSecs = ftToTime_t(lft);
- TIME_ZONE_INFORMATION tzi;
- GetTimeZoneInformation(&tzi);
- bool isDaylight = false;
- // Check for overflow
- qint64 localDiff = qAbs(localSecs - secsSinceEpoch);
- int daylightOffset = qAbs(tzi.Bias + tzi.DaylightBias) * 60;
- if (localDiff > daylightOffset)
- valid = false;
- else
- isDaylight = (localDiff == daylightOffset);
- if (daylightStatus) {
- if (isDaylight)
- *daylightStatus = QDateTimePrivate::DaylightTime;
- else
- *daylightStatus = QDateTimePrivate::StandardTime;
- }
- if (abbreviation) {
- if (isDaylight)
- *abbreviation = QString::fromWCharArray(tzi.DaylightName);
- else
- *abbreviation = QString::fromWCharArray(tzi.StandardName);
- }
- if (ok)
- *ok = valid;
-#else
// All other platforms provide standard C library time functions
tm local;
memset(&local, 0, sizeof(local)); // tm_[wy]day plus any non-standard fields
@@ -2329,7 +2254,6 @@ static qint64 qt_mktime(QDate *date, QTime *time, QDateTimePrivate::DaylightStat
if (ok)
*ok = false;
}
-#endif // Q_OS_WINCE
return ((qint64)secsSinceEpoch * 1000) + msec;
}
@@ -2345,23 +2269,7 @@ static bool qt_localtime(qint64 msecsSinceEpoch, QDate *localDate, QTime *localT
tm local;
bool valid = false;
-#if defined(Q_OS_WINCE)
- FILETIME utcTime = time_tToFt(secsSinceEpoch);
- FILETIME resultTime;
- valid = FileTimeToLocalFileTime(&utcTime , &resultTime);
- SYSTEMTIME sysTime;
- if (valid)
- valid = FileTimeToSystemTime(&resultTime , &sysTime);
-
- if (valid) {
- local.tm_sec = sysTime.wSecond;
- local.tm_min = sysTime.wMinute;
- local.tm_hour = sysTime.wHour;
- local.tm_mday = sysTime.wDay;
- local.tm_mon = sysTime.wMonth - 1;
- local.tm_year = sysTime.wYear - 1900;
- }
-#elif !defined(QT_NO_THREAD) && defined(_POSIX_THREAD_SAFE_FUNCTIONS)
+#if !defined(QT_NO_THREAD) && defined(_POSIX_THREAD_SAFE_FUNCTIONS)
// localtime() is required to work as if tzset() was called before it.
// localtime_r() does not have this requirement, so make an explicit call.
qt_tzset();
@@ -2574,240 +2482,423 @@ static qint64 localMSecsToEpochMSecs(qint64 localMsecs,
}
}
-/*****************************************************************************
- QDateTimePrivate member functions
- *****************************************************************************/
+static inline bool specCanBeSmall(Qt::TimeSpec spec)
+{
+ return spec == Qt::LocalTime || spec == Qt::UTC;
+}
-QDateTimePrivate::QDateTimePrivate(const QDate &toDate, const QTime &toTime, Qt::TimeSpec toSpec,
- int offsetSeconds)
- : m_msecs(0),
- m_spec(Qt::LocalTime),
- m_offsetFromUtc(0),
- m_status(0)
+static inline bool msecsCanBeSmall(qint64 msecs)
{
- setTimeSpec(toSpec, offsetSeconds);
- setDateTime(toDate, toTime);
+ if (!QDateTimeData::CanBeSmall)
+ return false;
+
+ ShortData sd;
+ sd.msecs = qintptr(msecs);
+ return sd.msecs == msecs;
}
-#ifndef QT_BOOTSTRAPPED
-QDateTimePrivate::QDateTimePrivate(const QDate &toDate, const QTime &toTime,
- const QTimeZone &toTimeZone)
- : m_spec(Qt::TimeZone),
- m_offsetFromUtc(0),
- m_timeZone(toTimeZone),
- m_status(0)
+static Q_DECL_CONSTEXPR inline
+QDateTimePrivate::StatusFlags mergeSpec(QDateTimePrivate::StatusFlags status, Qt::TimeSpec spec)
{
- setDateTime(toDate, toTime);
+ return QDateTimePrivate::StatusFlags((status & ~QDateTimePrivate::TimeSpecMask) |
+ (int(spec) << QDateTimePrivate::TimeSpecShift));
+}
+
+static Q_DECL_CONSTEXPR inline Qt::TimeSpec extractSpec(QDateTimePrivate::StatusFlags status)
+{
+ return Qt::TimeSpec((status & QDateTimePrivate::TimeSpecMask) >> QDateTimePrivate::TimeSpecShift);
+}
+
+// Set the Daylight Status if LocalTime set via msecs
+static Q_DECL_RELAXED_CONSTEXPR inline QDateTimePrivate::StatusFlags
+mergeDaylightStatus(QDateTimePrivate::StatusFlags sf, QDateTimePrivate::DaylightStatus status)
+{
+ sf &= ~QDateTimePrivate::DaylightMask;
+ if (status == QDateTimePrivate::DaylightTime) {
+ sf |= QDateTimePrivate::SetToDaylightTime;
+ } else if (status == QDateTimePrivate::StandardTime) {
+ sf |= QDateTimePrivate::SetToStandardTime;
+ }
+ return sf;
+}
+
+// Get the DST Status if LocalTime set via msecs
+static Q_DECL_RELAXED_CONSTEXPR inline
+QDateTimePrivate::DaylightStatus extractDaylightStatus(QDateTimePrivate::StatusFlags status)
+{
+ if (status & QDateTimePrivate::SetToDaylightTime)
+ return QDateTimePrivate::DaylightTime;
+ if (status & QDateTimePrivate::SetToStandardTime)
+ return QDateTimePrivate::StandardTime;
+ return QDateTimePrivate::UnknownDaylightTime;
}
-#endif // QT_BOOTSTRAPPED
-void QDateTimePrivate::setTimeSpec(Qt::TimeSpec spec, int offsetSeconds)
+static inline qint64 getMSecs(const QDateTimeData &d)
{
- clearValidDateTime();
- clearSetToDaylightStatus();
+ if (d.isShort()) {
+ // same as, but producing better code
+ //return d.data.msecs;
+ return qintptr(d.d) >> 8;
+ }
+ return d->m_msecs;
+}
+
+static inline QDateTimePrivate::StatusFlags getStatus(const QDateTimeData &d)
+{
+ if (d.isShort()) {
+ // same as, but producing better code
+ //return StatusFlag(d.data.status);
+ return QDateTimePrivate::StatusFlag(qintptr(d.d) & 0xFF);
+ }
+ return d->m_status;
+}
+
+static inline Qt::TimeSpec getSpec(const QDateTimeData &d)
+{
+ return extractSpec(getStatus(d));
+}
+
+// Refresh the LocalTime validity and offset
+static void refreshDateTime(QDateTimeData &d)
+{
+ auto status = getStatus(d);
+ const auto spec = extractSpec(status);
+ const qint64 msecs = getMSecs(d);
+ qint64 epochMSecs = 0;
+ int offsetFromUtc = 0;
+ QDate testDate;
+ QTime testTime;
+ Q_ASSERT(spec == Qt::TimeZone || spec == Qt::LocalTime);
#ifndef QT_BOOTSTRAPPED
- m_timeZone = QTimeZone();
+ // If not valid time zone then is invalid
+ if (spec == Qt::TimeZone) {
+ if (!d->m_timeZone.isValid())
+ status &= ~QDateTimePrivate::ValidDateTime;
+ else
+ epochMSecs = QDateTimePrivate::zoneMSecsToEpochMSecs(msecs, d->m_timeZone, &testDate, &testTime);
+ }
#endif // QT_BOOTSTRAPPED
- switch (spec) {
- case Qt::OffsetFromUTC:
- if (offsetSeconds == 0) {
- m_spec = Qt::UTC;
- m_offsetFromUtc = 0;
+ // If not valid date and time then is invalid
+ if (!(status & QDateTimePrivate::ValidDate) || !(status & QDateTimePrivate::ValidTime)) {
+ status &= ~QDateTimePrivate::ValidDateTime;
+ if (status & QDateTimePrivate::ShortData) {
+ d.data.status = status;
} else {
- m_spec = Qt::OffsetFromUTC;
- m_offsetFromUtc = offsetSeconds;
+ d->m_status = status;
+ d->m_offsetFromUtc = 0;
}
+ return;
+ }
+
+ // We have a valid date and time and a Qt::LocalTime or Qt::TimeZone that needs calculating
+ // LocalTime and TimeZone might fall into a "missing" DST transition hour
+ // Calling toEpochMSecs will adjust the returned date/time if it does
+ if (spec == Qt::LocalTime) {
+ auto dstStatus = extractDaylightStatus(status);
+ epochMSecs = localMSecsToEpochMSecs(msecs, &dstStatus, &testDate, &testTime);
+ }
+ if (timeToMSecs(testDate, testTime) == msecs) {
+ status |= QDateTimePrivate::ValidDateTime;
+ // Cache the offset to use in offsetFromUtc()
+ offsetFromUtc = (msecs - epochMSecs) / 1000;
+ } else {
+ status &= ~QDateTimePrivate::ValidDateTime;
+ }
+
+ if (status & QDateTimePrivate::ShortData) {
+ d.data.status = status;
+ } else {
+ d->m_status = status;
+ d->m_offsetFromUtc = offsetFromUtc;
+ }
+}
+
+// Check the UTC / offsetFromUTC validity
+static void checkValidDateTime(QDateTimeData &d)
+{
+ auto status = getStatus(d);
+ auto spec = extractSpec(status);
+ switch (spec) {
+ case Qt::OffsetFromUTC:
+ case Qt::UTC:
+ // for these, a valid date and a valid time imply a valid QDateTime
+ if ((status & QDateTimePrivate::ValidDate) && (status & QDateTimePrivate::ValidTime))
+ status |= QDateTimePrivate::ValidDateTime;
+ else
+ status &= ~QDateTimePrivate::ValidDateTime;
+ if (status & QDateTimePrivate::ShortData)
+ d.data.status = status;
+ else
+ d->m_status = status;
break;
case Qt::TimeZone:
- // Use system time zone instead
- m_spec = Qt::LocalTime;
- m_offsetFromUtc = 0;
+ case Qt::LocalTime:
+ // for these, we need to check whether the timezone is valid and whether
+ // the time is valid in that timezone. Expensive, but no other option.
+ refreshDateTime(d);
+ break;
+ }
+}
+
+static void setTimeSpec(QDateTimeData &d, Qt::TimeSpec spec, int offsetSeconds)
+{
+ auto status = getStatus(d);
+ status &= ~(QDateTimePrivate::ValidDateTime | QDateTimePrivate::DaylightMask |
+ QDateTimePrivate::TimeSpecMask);
+
+ switch (spec) {
+ case Qt::OffsetFromUTC:
+ if (offsetSeconds == 0)
+ spec = Qt::UTC;
break;
+ case Qt::TimeZone:
+ // Use system time zone instead
+ spec = Qt::LocalTime;
+ // fallthrough
case Qt::UTC:
case Qt::LocalTime:
- m_spec = spec;
- m_offsetFromUtc = 0;
+ offsetSeconds = 0;
break;
}
+
+ status = mergeSpec(status, spec);
+ if (d.isShort() && offsetSeconds == 0) {
+ d.data.status = status;
+ } else {
+ d.detach();
+ d->m_status = status & ~QDateTimePrivate::ShortData;
+ d->m_offsetFromUtc = offsetSeconds;
+#ifndef QT_BOOTSTRAPPED
+ d->m_timeZone = QTimeZone();
+#endif // QT_BOOTSTRAPPED
+ }
}
-void QDateTimePrivate::setDateTime(const QDate &date, const QTime &time)
+static void setDateTime(QDateTimeData &d, const QDate &date, const QTime &time)
{
// If the date is valid and the time is not we set time to 00:00:00
QTime useTime = time;
if (!useTime.isValid() && date.isValid())
useTime = QTime::fromMSecsSinceStartOfDay(0);
- StatusFlags newStatus;
+ QDateTimePrivate::StatusFlags newStatus = 0;
// Set date value and status
qint64 days = 0;
if (date.isValid()) {
days = date.toJulianDay() - JULIAN_DAY_FOR_EPOCH;
- newStatus = ValidDate;
- } else if (date.isNull()) {
- newStatus = NullDate;
+ newStatus = QDateTimePrivate::ValidDate;
}
// Set time value and status
int ds = 0;
if (useTime.isValid()) {
ds = useTime.msecsSinceStartOfDay();
- newStatus |= ValidTime;
- } else if (time.isNull()) {
- newStatus |= NullTime;
+ newStatus |= QDateTimePrivate::ValidTime;
}
// Set msecs serial value
- m_msecs = (days * MSECS_PER_DAY) + ds;
- m_status = newStatus;
+ qint64 msecs = (days * MSECS_PER_DAY) + ds;
+ if (d.isShort()) {
+ // let's see if we can keep this short
+ if (msecsCanBeSmall(msecs)) {
+ // yes, we can
+ d.data.msecs = qintptr(msecs);
+ d.data.status &= ~(QDateTimePrivate::ValidityMask | QDateTimePrivate::DaylightMask);
+ d.data.status |= newStatus;
+ } else {
+ // nope...
+ d.detach();
+ }
+ }
+ if (!d.isShort()) {
+ d.detach();
+ d->m_msecs = msecs;
+ d->m_status &= ~(QDateTimePrivate::ValidityMask | QDateTimePrivate::DaylightMask);
+ d->m_status |= newStatus;
+ }
// Set if date and time are valid
- checkValidDateTime();
+ checkValidDateTime(d);
}
-QPair<QDate, QTime> QDateTimePrivate::getDateTime() const
+static QPair<QDate, QTime> getDateTime(const QDateTimeData &d)
{
QPair<QDate, QTime> result;
- msecsToTime(m_msecs, &result.first, &result.second);
+ qint64 msecs = getMSecs(d);
+ auto status = getStatus(d);
+ msecsToTime(msecs, &result.first, &result.second);
- if (isNullDate())
+ if (!status.testFlag(QDateTimePrivate::ValidDate))
result.first = QDate();
- if (isNullTime())
+ if (!status.testFlag(QDateTimePrivate::ValidTime))
result.second = QTime();
return result;
}
-// Set the Daylight Status if LocalTime set via msecs
-void QDateTimePrivate::setDaylightStatus(QDateTimePrivate::DaylightStatus status)
-{
- if (status == DaylightTime) {
- m_status = m_status & ~SetToStandardTime;
- m_status = m_status | SetToDaylightTime;
- } else if (status == StandardTime) {
- m_status = m_status & ~SetToDaylightTime;
- m_status = m_status | SetToStandardTime;
+/*****************************************************************************
+ QDateTime::Data member functions
+ *****************************************************************************/
+
+inline QDateTime::Data::Data()
+{
+ // default-constructed data has a special exception:
+ // it can be small even if CanBeSmall == false
+ // (optimization so we don't allocate memory in the default constructor)
+ quintptr value = quintptr(mergeSpec(QDateTimePrivate::ShortData, Qt::LocalTime));
+ d = reinterpret_cast<QDateTimePrivate *>(value);
+}
+
+inline QDateTime::Data::Data(Qt::TimeSpec spec)
+{
+ if (CanBeSmall && Q_LIKELY(specCanBeSmall(spec))) {
+ d = reinterpret_cast<QDateTimePrivate *>(quintptr(mergeSpec(QDateTimePrivate::ShortData, spec)));
} else {
- clearSetToDaylightStatus();
+ // the structure is too small, we need to detach
+ d = new QDateTimePrivate;
+ d->ref.ref();
+ d->m_status = mergeSpec(0, spec);
}
}
-// Get the DST Status if LocalTime set via msecs
-QDateTimePrivate::DaylightStatus QDateTimePrivate::daylightStatus() const
+inline QDateTime::Data::Data(const Data &other)
+ : d(other.d)
{
- if ((m_status & SetToDaylightTime) == SetToDaylightTime)
- return DaylightTime;
- if ((m_status & SetToStandardTime) == SetToStandardTime)
- return StandardTime;
- return UnknownDaylightTime;
+ if (!isShort()) {
+ // check if we could shrink
+ if (specCanBeSmall(extractSpec(d->m_status)) && msecsCanBeSmall(d->m_msecs)) {
+ ShortData sd;
+ sd.msecs = qintptr(d->m_msecs);
+ sd.status = d->m_status | QDateTimePrivate::ShortData;
+ data = sd;
+ } else {
+ // no, have to keep it big
+ d->ref.ref();
+ }
+ }
}
-qint64 QDateTimePrivate::toMSecsSinceEpoch() const
+inline QDateTime::Data::Data(Data &&other)
+ : d(other.d)
{
- switch (m_spec) {
- case Qt::OffsetFromUTC:
- case Qt::UTC:
- return (m_msecs - (m_offsetFromUtc * 1000));
+ // reset the other to a short state
+ Data dummy;
+ Q_ASSERT(dummy.isShort());
+ other.d = dummy.d;
+}
- case Qt::LocalTime: {
- // recalculate the local timezone
- DaylightStatus status = daylightStatus();
- return localMSecsToEpochMSecs(m_msecs, &status);
- }
+inline QDateTime::Data &QDateTime::Data::operator=(const Data &other)
+{
+ if (d == other.d)
+ return *this;
- case Qt::TimeZone:
-#ifdef QT_BOOTSTRAPPED
- return 0;
-#else
- return zoneMSecsToEpochMSecs(m_msecs, m_timeZone);
-#endif
+ auto x = d;
+ d = other.d;
+ if (!other.isShort()) {
+ // check if we could shrink
+ if (specCanBeSmall(extractSpec(other.d->m_status)) && msecsCanBeSmall(other.d->m_msecs)) {
+ ShortData sd;
+ sd.msecs = qintptr(other.d->m_msecs);
+ sd.status = other.d->m_status | QDateTimePrivate::ShortData;
+ data = sd;
+ } else {
+ // no, have to keep it big
+ other.d->ref.ref();
+ }
}
- Q_UNREACHABLE();
- return 0;
+
+ if (!(quintptr(x) & QDateTimePrivate::ShortData) && !x->ref.deref())
+ delete x;
+ return *this;
}
-// Check the UTC / offsetFromUTC validity
-void QDateTimePrivate::checkValidDateTime()
+inline QDateTime::Data::~Data()
{
- switch (m_spec) {
- case Qt::OffsetFromUTC:
- case Qt::UTC:
- // for these, a valid date and a valid time imply a valid QDateTime
- if (isValidDate() && isValidTime())
- setValidDateTime();
- else
- clearValidDateTime();
- break;
- case Qt::TimeZone:
- case Qt::LocalTime:
- // for these, we need to check whether the timezone is valid and whether
- // the time is valid in that timezone. Expensive, but no other option.
- refreshDateTime();
- break;
- }
+ if (!isShort() && !d->ref.deref())
+ delete d;
}
-// Refresh the LocalTime validity and offset
-void QDateTimePrivate::refreshDateTime()
+inline bool QDateTime::Data::isShort() const
{
- switch (m_spec) {
- case Qt::OffsetFromUTC:
- case Qt::UTC:
- // Always set by setDateTime so just return
- return;
- case Qt::TimeZone:
- case Qt::LocalTime:
- break;
- }
-
- // If not valid date and time then is invalid
- if (!isValidDate() || !isValidTime()) {
- clearValidDateTime();
- m_offsetFromUtc = 0;
- return;
- }
+ bool b = quintptr(d) & QDateTimePrivate::ShortData;
-#ifndef QT_BOOTSTRAPPED
- // If not valid time zone then is invalid
- if (m_spec == Qt::TimeZone && !m_timeZone.isValid()) {
- clearValidDateTime();
- m_offsetFromUtc = 0;
- return;
- }
-#endif // QT_BOOTSTRAPPED
+ // even if CanBeSmall = false, we have short data for a default-constructed
+ // QDateTime object. But it's unlikely.
+ if (CanBeSmall)
+ return Q_LIKELY(b);
+ return Q_UNLIKELY(b);
+}
- // We have a valid date and time and a Qt::LocalTime or Qt::TimeZone that needs calculating
- // LocalTime and TimeZone might fall into a "missing" DST transition hour
- // Calling toEpochMSecs will adjust the returned date/time if it does
- QDate testDate;
- QTime testTime;
- qint64 epochMSecs = 0;
- if (m_spec == Qt::LocalTime) {
- DaylightStatus status = daylightStatus();
- epochMSecs = localMSecsToEpochMSecs(m_msecs, &status, &testDate, &testTime);
-#ifndef QT_BOOTSTRAPPED
- } else {
- epochMSecs = zoneMSecsToEpochMSecs(m_msecs, m_timeZone, &testDate, &testTime);
-#endif // QT_BOOTSTRAPPED
- }
- if (timeToMSecs(testDate, testTime) == m_msecs) {
- setValidDateTime();
- // Cache the offset to use in toMSecsSinceEpoch()
- m_offsetFromUtc = (m_msecs - epochMSecs) / 1000;
+inline void QDateTime::Data::detach()
+{
+ QDateTimePrivate *x;
+ bool wasShort = isShort();
+ if (wasShort) {
+ // force enlarging
+ x = new QDateTimePrivate;
+ x->m_status = QDateTimePrivate::StatusFlag(data.status & ~QDateTimePrivate::ShortData);
+ x->m_msecs = data.msecs;
} else {
- clearValidDateTime();
- m_offsetFromUtc = 0;
+ if (d->ref.load() == 1)
+ return;
+
+ x = new QDateTimePrivate(*d);
}
+
+ x->ref.store(1);
+ if (!wasShort && !d->ref.deref())
+ delete d;
+ d = x;
+}
+
+inline const QDateTimePrivate *QDateTime::Data::operator->() const
+{
+ Q_ASSERT(!isShort());
+ return d;
+}
+
+inline QDateTimePrivate *QDateTime::Data::operator->()
+{
+ // should we attempt to detach here?
+ Q_ASSERT(!isShort());
+ Q_ASSERT(d->ref.load() == 1);
+ return d;
+}
+
+/*****************************************************************************
+ QDateTimePrivate member functions
+ *****************************************************************************/
+
+Q_NEVER_INLINE
+QDateTime::Data QDateTimePrivate::create(const QDate &toDate, const QTime &toTime, Qt::TimeSpec toSpec,
+ int offsetSeconds)
+{
+ QDateTime::Data result(toSpec);
+ setTimeSpec(result, toSpec, offsetSeconds);
+ setDateTime(result, toDate, toTime);
+ return result;
}
#ifndef QT_BOOTSTRAPPED
+inline QDateTime::Data QDateTimePrivate::create(const QDate &toDate, const QTime &toTime,
+ const QTimeZone &toTimeZone)
+{
+ QDateTime::Data result(Qt::TimeZone);
+ Q_ASSERT(!result.isShort());
+
+ result.d->m_status = mergeSpec(result.d->m_status, Qt::TimeZone);
+ result.d->m_timeZone = toTimeZone;
+ setDateTime(result, toDate, toTime);
+ return result;
+}
+
// Convert a TimeZone time expressed in zone msecs encoding into a UTC epoch msecs
-qint64 QDateTimePrivate::zoneMSecsToEpochMSecs(qint64 zoneMSecs, const QTimeZone &zone,
- QDate *localDate, QTime *localTime)
+inline qint64 QDateTimePrivate::zoneMSecsToEpochMSecs(qint64 zoneMSecs, const QTimeZone &zone,
+ QDate *localDate, QTime *localTime)
{
// Get the effective data from QTimeZone
QTimeZonePrivate::Data data = zone.d->dataForLocalTime(zoneMSecs);
@@ -2958,8 +3049,7 @@ qint64 QDateTimePrivate::zoneMSecsToEpochMSecs(qint64 zoneMSecs, const QTimeZone
\sa isValid()
*/
-QDateTime::QDateTime()
- : d(*defaultDateTimePrivate())
+QDateTime::QDateTime() Q_DECL_NOEXCEPT_EXPR(Data::CanBeSmall)
{
}
@@ -2970,7 +3060,7 @@ QDateTime::QDateTime()
*/
QDateTime::QDateTime(const QDate &date)
- : d(new QDateTimePrivate(date, QTime(0, 0, 0), Qt::LocalTime, 0))
+ : d(QDateTimePrivate::create(date, QTime(0, 0, 0), Qt::LocalTime, 0))
{
}
@@ -2990,7 +3080,7 @@ QDateTime::QDateTime(const QDate &date)
*/
QDateTime::QDateTime(const QDate &date, const QTime &time, Qt::TimeSpec spec)
- : d(new QDateTimePrivate(date, time, spec, 0))
+ : d(QDateTimePrivate::create(date, time, spec, 0))
{
}
@@ -3013,7 +3103,7 @@ QDateTime::QDateTime(const QDate &date, const QTime &time, Qt::TimeSpec spec)
*/
QDateTime::QDateTime(const QDate &date, const QTime &time, Qt::TimeSpec spec, int offsetSeconds)
- : d(new QDateTimePrivate(date, time, spec, offsetSeconds))
+ : d(QDateTimePrivate::create(date, time, spec, offsetSeconds))
{
}
@@ -3030,7 +3120,7 @@ QDateTime::QDateTime(const QDate &date, const QTime &time, Qt::TimeSpec spec, in
*/
QDateTime::QDateTime(const QDate &date, const QTime &time, const QTimeZone &timeZone)
- : d(new QDateTimePrivate(date, time, timeZone))
+ : d(QDateTimePrivate::create(date, time, timeZone))
{
}
#endif // QT_BOOTSTRAPPED
@@ -3038,13 +3128,22 @@ QDateTime::QDateTime(const QDate &date, const QTime &time, const QTimeZone &time
/*!
Constructs a copy of the \a other datetime.
*/
-
-QDateTime::QDateTime(const QDateTime &other)
+QDateTime::QDateTime(const QDateTime &other) Q_DECL_NOTHROW
: d(other.d)
{
}
/*!
+ \since 5.8
+ Moves the content of the temporary \a other datetime to this object and
+ leaves \a other in an unspecified (but proper) state.
+*/
+QDateTime::QDateTime(QDateTime &&other) Q_DECL_NOTHROW
+ : d(std::move(other.d))
+{
+}
+
+/*!
Destroys the datetime.
*/
QDateTime::~QDateTime()
@@ -3056,7 +3155,7 @@ QDateTime::~QDateTime()
copy.
*/
-QDateTime &QDateTime::operator=(const QDateTime &other)
+QDateTime &QDateTime::operator=(const QDateTime &other) Q_DECL_NOTHROW
{
d = other.d;
return *this;
@@ -3078,7 +3177,9 @@ QDateTime &QDateTime::operator=(const QDateTime &other)
bool QDateTime::isNull() const
{
- return d->isNullDate() && d->isNullTime();
+ auto status = getStatus(d);
+ return !status.testFlag(QDateTimePrivate::ValidDate) &&
+ !status.testFlag(QDateTimePrivate::ValidTime);
}
/*!
@@ -3095,7 +3196,8 @@ bool QDateTime::isNull() const
bool QDateTime::isValid() const
{
- return (d->isValidDateTime());
+ auto status = getStatus(d);
+ return status & QDateTimePrivate::ValidDateTime;
}
/*!
@@ -3106,10 +3208,11 @@ bool QDateTime::isValid() const
QDate QDateTime::date() const
{
- if (d->isNullDate())
+ auto status = getStatus(d);
+ if (!status.testFlag(QDateTimePrivate::ValidDate))
return QDate();
QDate dt;
- msecsToTime(d->m_msecs, &dt, 0);
+ msecsToTime(getMSecs(d), &dt, 0);
return dt;
}
@@ -3121,10 +3224,11 @@ QDate QDateTime::date() const
QTime QDateTime::time() const
{
- if (d->isNullTime())
+ auto status = getStatus(d);
+ if (!status.testFlag(QDateTimePrivate::ValidTime))
return QTime();
QTime tm;
- msecsToTime(d->m_msecs, 0, &tm);
+ msecsToTime(getMSecs(d), 0, &tm);
return tm;
}
@@ -3136,7 +3240,7 @@ QTime QDateTime::time() const
Qt::TimeSpec QDateTime::timeSpec() const
{
- return d->m_spec;
+ return getSpec(d);
}
#ifndef QT_BOOTSTRAPPED
@@ -3154,7 +3258,7 @@ Qt::TimeSpec QDateTime::timeSpec() const
QTimeZone QDateTime::timeZone() const
{
- switch (d->m_spec) {
+ switch (getSpec(d)) {
case Qt::UTC:
return QTimeZone::utc();
case Qt::OffsetFromUTC:
@@ -3189,7 +3293,20 @@ QTimeZone QDateTime::timeZone() const
int QDateTime::offsetFromUtc() const
{
- return d->m_offsetFromUtc;
+ if (!d.isShort())
+ return d->m_offsetFromUtc;
+ if (!isValid())
+ return 0;
+
+ auto spec = getSpec(d);
+ if (spec == Qt::LocalTime) {
+ // we didn't cache the value, so we need to calculate it now...
+ qint64 msecs = getMSecs(d);
+ return (msecs - toMSecsSinceEpoch()) / 1000;
+ }
+
+ Q_ASSERT(spec == Qt::UTC);
+ return 0;
}
/*!
@@ -3215,7 +3332,7 @@ int QDateTime::offsetFromUtc() const
QString QDateTime::timeZoneAbbreviation() const
{
- switch (d->m_spec) {
+ switch (getSpec(d)) {
case Qt::UTC:
return QTimeZonePrivate::utcQString();
case Qt::OffsetFromUTC:
@@ -3224,12 +3341,12 @@ QString QDateTime::timeZoneAbbreviation() const
#ifdef QT_BOOTSTRAPPED
break;
#else
- return d->m_timeZone.d->abbreviation(d->toMSecsSinceEpoch());
+ return d->m_timeZone.d->abbreviation(toMSecsSinceEpoch());
#endif // QT_BOOTSTRAPPED
case Qt::LocalTime: {
QString abbrev;
- QDateTimePrivate::DaylightStatus status = d->daylightStatus();
- localMSecsToEpochMSecs(d->m_msecs, &status, 0, 0, &abbrev);
+ auto status = extractDaylightStatus(getStatus(d));
+ localMSecsToEpochMSecs(getMSecs(d), &status, 0, 0, &abbrev);
return abbrev;
}
}
@@ -3249,7 +3366,7 @@ QString QDateTime::timeZoneAbbreviation() const
bool QDateTime::isDaylightTime() const
{
- switch (d->m_spec) {
+ switch (getSpec(d)) {
case Qt::UTC:
case Qt::OffsetFromUTC:
return false;
@@ -3260,9 +3377,9 @@ bool QDateTime::isDaylightTime() const
return d->m_timeZone.d->isDaylightTime(toMSecsSinceEpoch());
#endif // QT_BOOTSTRAPPED
case Qt::LocalTime: {
- QDateTimePrivate::DaylightStatus status = d->daylightStatus();
+ auto status = extractDaylightStatus(getStatus(d));
if (status == QDateTimePrivate::UnknownDaylightTime)
- localMSecsToEpochMSecs(d->m_msecs, &status);
+ localMSecsToEpochMSecs(getMSecs(d), &status);
return (status == QDateTimePrivate::DaylightTime);
}
}
@@ -3278,7 +3395,7 @@ bool QDateTime::isDaylightTime() const
void QDateTime::setDate(const QDate &date)
{
- d->setDateTime(date, time());
+ setDateTime(d, date, time());
}
/*!
@@ -3296,7 +3413,7 @@ void QDateTime::setDate(const QDate &date)
void QDateTime::setTime(const QTime &time)
{
- d->setDateTime(date(), time);
+ setDateTime(d, date(), time);
}
/*!
@@ -3317,9 +3434,8 @@ void QDateTime::setTime(const QTime &time)
void QDateTime::setTimeSpec(Qt::TimeSpec spec)
{
- QDateTimePrivate *d = this->d.data(); // detaches (and shadows d)
- d->setTimeSpec(spec, 0);
- d->checkValidDateTime();
+ QT_PREPEND_NAMESPACE(setTimeSpec(d, spec, 0));
+ checkValidDateTime(d);
}
/*!
@@ -3339,9 +3455,8 @@ void QDateTime::setTimeSpec(Qt::TimeSpec spec)
void QDateTime::setOffsetFromUtc(int offsetSeconds)
{
- QDateTimePrivate *d = this->d.data(); // detaches (and shadows d)
- d->setTimeSpec(Qt::OffsetFromUTC, offsetSeconds);
- d->checkValidDateTime();
+ QT_PREPEND_NAMESPACE(setTimeSpec(d, Qt::OffsetFromUTC, offsetSeconds));
+ checkValidDateTime(d);
}
#ifndef QT_BOOTSTRAPPED
@@ -3358,11 +3473,11 @@ void QDateTime::setOffsetFromUtc(int offsetSeconds)
void QDateTime::setTimeZone(const QTimeZone &toZone)
{
- QDateTimePrivate *d = this->d.data(); // detaches (and shadows d)
- d->m_spec = Qt::TimeZone;
+ d.detach(); // always detach
+ d->m_status = mergeSpec(d->m_status, Qt::TimeZone);
d->m_offsetFromUtc = 0;
d->m_timeZone = toZone;
- d->refreshDateTime();
+ refreshDateTime(d);
}
#endif // QT_BOOTSTRAPPED
@@ -3379,44 +3494,85 @@ void QDateTime::setTimeZone(const QTimeZone &toZone)
this object is not valid. However, for all valid dates, this function
returns a unique value.
- \sa toTime_t(), setMSecsSinceEpoch()
+ \sa toSecsSinceEpoch(), setMSecsSinceEpoch()
*/
qint64 QDateTime::toMSecsSinceEpoch() const
{
- return d->toMSecsSinceEpoch();
+ switch (getSpec(d)) {
+ case Qt::UTC:
+ return getMSecs(d);
+
+ case Qt::OffsetFromUTC:
+ return d->m_msecs - (d->m_offsetFromUtc * 1000);
+
+ case Qt::LocalTime: {
+ // recalculate the local timezone
+ auto status = extractDaylightStatus(getStatus(d));
+ return localMSecsToEpochMSecs(getMSecs(d), &status);
+ }
+
+ case Qt::TimeZone:
+#ifdef QT_BOOTSTRAPPED
+ return 0;
+#else
+ return QDateTimePrivate::zoneMSecsToEpochMSecs(d->m_msecs, d->m_timeZone);
+#endif
+ }
+ Q_UNREACHABLE();
+ return 0;
+}
+
+/*!
+ \since 5.8
+
+ Returns the datetime as the number of seconds that have passed since
+ 1970-01-01T00:00:00.000, Coordinated Universal Time (Qt::UTC).
+
+ On systems that do not support time zones, this function will
+ behave as if local time were Qt::UTC.
+
+ The behavior for this function is undefined if the datetime stored in
+ this object is not valid. However, for all valid dates, this function
+ returns a unique value.
+
+ \sa toMSecsSinceEpoch(), setSecsSinceEpoch()
+*/
+qint64 QDateTime::toSecsSinceEpoch() const
+{
+ return toMSecsSinceEpoch() / 1000;
}
+#if QT_DEPRECATED_SINCE(5, 8)
/*!
+ \deprecated
+
Returns the datetime as the number of seconds that have passed
since 1970-01-01T00:00:00, Coordinated Universal Time (Qt::UTC).
On systems that do not support time zones, this function will
behave as if local time were Qt::UTC.
- \note This function returns a 32-bit unsigned integer, so it does not
- support dates before 1970, but it does support dates after
- 2038-01-19T03:14:06, which may not be valid time_t values. Be careful
- when passing those time_t values to system functions, which could
- interpret them as negative dates.
+ \note This function returns a 32-bit unsigned integer and is deprecated.
If the date is outside the range 1970-01-01T00:00:00 to
2106-02-07T06:28:14, this function returns -1 cast to an unsigned integer
(i.e., 0xFFFFFFFF).
- To get an extended range, use toMSecsSinceEpoch().
+ To get an extended range, use toMSecsSinceEpoch() or toSecsSinceEpoch().
- \sa toMSecsSinceEpoch(), setTime_t()
+ \sa toSecsSinceEpoch(), toMSecsSinceEpoch(), setTime_t()
*/
uint QDateTime::toTime_t() const
{
if (!isValid())
return uint(-1);
- qint64 retval = d->toMSecsSinceEpoch() / 1000;
+ qint64 retval = toMSecsSinceEpoch() / 1000;
if (quint64(retval) >= Q_UINT64_C(0xFFFFFFFF))
return uint(-1);
return uint(retval);
}
+#endif
/*!
\since 4.7
@@ -3430,65 +3586,98 @@ uint QDateTime::toTime_t() const
(\c{std::numeric_limits<qint64>::min()}) to \a msecs will result in
undefined behavior.
- \sa toMSecsSinceEpoch(), setTime_t()
+ \sa toMSecsSinceEpoch(), setSecsSinceEpoch()
*/
void QDateTime::setMSecsSinceEpoch(qint64 msecs)
{
- QDateTimePrivate *d = this->d.data(); // detaches (and shadows d)
+ const auto spec = getSpec(d);
+ auto status = getStatus(d);
- d->m_status = 0;
- switch (d->m_spec) {
+ status &= ~QDateTimePrivate::ValidityMask;
+ switch (spec) {
case Qt::UTC:
- d->m_msecs = msecs;
- d->m_status = d->m_status
+ status = status
| QDateTimePrivate::ValidDate
| QDateTimePrivate::ValidTime
| QDateTimePrivate::ValidDateTime;
break;
case Qt::OffsetFromUTC:
- d->m_msecs = msecs + (d->m_offsetFromUtc * 1000);
- d->m_status = d->m_status
+ msecs = msecs + (d->m_offsetFromUtc * 1000);
+ status = status
| QDateTimePrivate::ValidDate
| QDateTimePrivate::ValidTime
| QDateTimePrivate::ValidDateTime;
break;
case Qt::TimeZone:
+ Q_ASSERT(!d.isShort());
#ifndef QT_BOOTSTRAPPED
// Docs state any LocalTime before 1970-01-01 will *not* have any DST applied
// but all affected times afterwards will have DST applied.
+ d.detach();
if (msecs >= 0)
d->m_offsetFromUtc = d->m_timeZone.d->offsetFromUtc(msecs);
else
d->m_offsetFromUtc = d->m_timeZone.d->standardTimeOffset(msecs);
- d->m_msecs = msecs + (d->m_offsetFromUtc * 1000);
- d->m_status = d->m_status
+ msecs = msecs + (d->m_offsetFromUtc * 1000);
+ status = status
| QDateTimePrivate::ValidDate
| QDateTimePrivate::ValidTime
| QDateTimePrivate::ValidDateTime;
- d->refreshDateTime();
#endif // QT_BOOTSTRAPPED
break;
case Qt::LocalTime: {
QDate dt;
QTime tm;
- QDateTimePrivate::DaylightStatus status;
- epochMSecsToLocalTime(msecs, &dt, &tm, &status);
- d->setDateTime(dt, tm);
- d->setDaylightStatus(status);
- d->refreshDateTime();
+ QDateTimePrivate::DaylightStatus dstStatus;
+ epochMSecsToLocalTime(msecs, &dt, &tm, &dstStatus);
+ setDateTime(d, dt, tm);
+ msecs = getMSecs(d);
+ status = mergeDaylightStatus(getStatus(d), dstStatus);
break;
}
}
+
+ if (msecsCanBeSmall(msecs) && d.isShort()) {
+ // we can keep short
+ d.data.msecs = qintptr(msecs);
+ d.data.status = status;
+ } else {
+ d.detach();
+ d->m_status = status;
+ d->m_msecs = msecs;
+ }
+
+ if (spec == Qt::LocalTime || spec == Qt::TimeZone)
+ refreshDateTime(d);
}
/*!
+ \since 5.8
+
+ Sets the date and time given the number of seconds \a secs that have
+ passed since 1970-01-01T00:00:00.000, Coordinated Universal Time
+ (Qt::UTC). On systems that do not support time zones this function
+ will behave as if local time were Qt::UTC.
+
+ \sa toSecsSinceEpoch(), setMSecsSinceEpoch()
+*/
+void QDateTime::setSecsSinceEpoch(qint64 secs)
+{
+ setMSecsSinceEpoch(secs * 1000);
+}
+
+#if QT_DEPRECATED_SINCE(5, 8)
+/*!
\fn void QDateTime::setTime_t(uint seconds)
+ \deprecated
Sets the date and time given the number of \a seconds that have
passed since 1970-01-01T00:00:00, Coordinated Universal Time
(Qt::UTC). On systems that do not support time zones this function
will behave as if local time were Qt::UTC.
+ \note This function is deprecated. For new code, use setSecsSinceEpoch().
+
\sa toTime_t()
*/
@@ -3496,6 +3685,7 @@ void QDateTime::setTime_t(uint secsSince1Jan1970UTC)
{
setMSecsSinceEpoch((qint64)secsSince1Jan1970UTC * 1000);
}
+#endif
#ifndef QT_NO_DATESTRING
/*!
@@ -3565,13 +3755,13 @@ QString QDateTime::toString(Qt::DateFormat format) const
return QLocale().toString(*this, QLocale::LongFormat);
case Qt::RFC2822Date: {
buf = QLocale::c().toString(*this, QStringLiteral("dd MMM yyyy hh:mm:ss "));
- buf += toOffsetString(Qt::TextDate, d->m_offsetFromUtc);
+ buf += toOffsetString(Qt::TextDate, offsetFromUtc());
return buf;
}
default:
#ifndef QT_NO_TEXTDATE
case Qt::TextDate: {
- const QPair<QDate, QTime> p = d->getDateTime();
+ const QPair<QDate, QTime> p = getDateTime(d);
const QDate &dt = p.first;
const QTime &tm = p.second;
//We cant use date.toString(Qt::TextDate) as we need to insert the time before the year
@@ -3582,14 +3772,14 @@ QString QDateTime::toString(Qt::DateFormat format) const
.arg(dt.year());
if (timeSpec() != Qt::LocalTime) {
buf += QLatin1String(" GMT");
- if (d->m_spec == Qt::OffsetFromUTC)
- buf += toOffsetString(Qt::TextDate, d->m_offsetFromUtc);
+ if (getSpec(d) == Qt::OffsetFromUTC)
+ buf += toOffsetString(Qt::TextDate, offsetFromUtc());
}
return buf;
}
#endif
case Qt::ISODate: {
- const QPair<QDate, QTime> p = d->getDateTime();
+ const QPair<QDate, QTime> p = getDateTime(d);
const QDate &dt = p.first;
const QTime &tm = p.second;
buf = dt.toString(Qt::ISODate);
@@ -3597,12 +3787,12 @@ QString QDateTime::toString(Qt::DateFormat format) const
return QString(); // failed to convert
buf += QLatin1Char('T');
buf += tm.toString(Qt::ISODate);
- switch (d->m_spec) {
+ switch (getSpec(d)) {
case Qt::UTC:
buf += QLatin1Char('Z');
break;
case Qt::OffsetFromUTC:
- buf += toOffsetString(Qt::ISODate, d->m_offsetFromUtc);
+ buf += toOffsetString(Qt::ISODate, offsetFromUtc());
break;
default:
break;
@@ -3691,12 +3881,7 @@ QString QDateTime::toString(const QString& format) const
}
#endif //QT_NO_DATESTRING
-static void massageAdjustedDateTime(Qt::TimeSpec spec,
-#ifndef QT_BOOTSTRAPPED
- const QTimeZone &zone,
-#endif // QT_BOOTSTRAPPED
- QDate *date,
- QTime *time)
+static inline void massageAdjustedDateTime(const QDateTimeData &d, QDate *date, QTime *time)
{
/*
If we have just adjusted to a day with a DST transition, our given time
@@ -3706,24 +3891,20 @@ static void massageAdjustedDateTime(Qt::TimeSpec spec,
to its DST-ness); but for a time in spring's missing hour it'll adjust the
time while picking a DST-ness. (Handling of autumn is trickier, as either
DST-ness is valid, without adjusting the time. We might want to propagate
- d->daylightStatus() in that case, but it's hard to do so without breaking
+ the daylight status in that case, but it's hard to do so without breaking
(far more common) other cases; and it makes little difference, as the two
answers do then differ only in DST-ness.)
*/
+ auto spec = getSpec(d);
if (spec == Qt::LocalTime) {
QDateTimePrivate::DaylightStatus status = QDateTimePrivate::UnknownDaylightTime;
localMSecsToEpochMSecs(timeToMSecs(*date, *time), &status, date, time);
#ifndef QT_BOOTSTRAPPED
} else if (spec == Qt::TimeZone) {
- QDateTimePrivate::zoneMSecsToEpochMSecs(timeToMSecs(*date, *time), zone, date, time);
+ QDateTimePrivate::zoneMSecsToEpochMSecs(timeToMSecs(*date, *time), d->m_timeZone, date, time);
#endif // QT_BOOTSTRAPPED
}
}
-#ifdef QT_BOOTSTRAPPED // Avoid duplicate #if-ery in uses.
-#define MASSAGEADJUSTEDDATETIME(s, z, d, t) massageAdjustedDateTime(s, d, t)
-#else
-#define MASSAGEADJUSTEDDATETIME(s, z, d, t) massageAdjustedDateTime(s, z, d, t)
-#endif // QT_BOOTSTRAPPED
/*!
Returns a QDateTime object containing a datetime \a ndays days
@@ -3742,12 +3923,12 @@ static void massageAdjustedDateTime(Qt::TimeSpec spec,
QDateTime QDateTime::addDays(qint64 ndays) const
{
QDateTime dt(*this);
- QPair<QDate, QTime> p = d->getDateTime();
+ QPair<QDate, QTime> p = getDateTime(d);
QDate &date = p.first;
QTime &time = p.second;
date = date.addDays(ndays);
- MASSAGEADJUSTEDDATETIME(d->m_spec, d->m_timeZone, &date, &time);
- dt.d->setDateTime(date, time);
+ massageAdjustedDateTime(dt.d, &date, &time);
+ setDateTime(dt.d, date, time);
return dt;
}
@@ -3768,12 +3949,12 @@ QDateTime QDateTime::addDays(qint64 ndays) const
QDateTime QDateTime::addMonths(int nmonths) const
{
QDateTime dt(*this);
- QPair<QDate, QTime> p = d->getDateTime();
+ QPair<QDate, QTime> p = getDateTime(d);
QDate &date = p.first;
QTime &time = p.second;
date = date.addMonths(nmonths);
- MASSAGEADJUSTEDDATETIME(d->m_spec, d->m_timeZone, &date, &time);
- dt.d->setDateTime(date, time);
+ massageAdjustedDateTime(dt.d, &date, &time);
+ setDateTime(dt.d, date, time);
return dt;
}
@@ -3794,15 +3975,14 @@ QDateTime QDateTime::addMonths(int nmonths) const
QDateTime QDateTime::addYears(int nyears) const
{
QDateTime dt(*this);
- QPair<QDate, QTime> p = d->getDateTime();
+ QPair<QDate, QTime> p = getDateTime(d);
QDate &date = p.first;
QTime &time = p.second;
date = date.addYears(nyears);
- MASSAGEADJUSTEDDATETIME(d->m_spec, d->m_timeZone, &date, &time);
- dt.d->setDateTime(date, time);
+ massageAdjustedDateTime(dt.d, &date, &time);
+ setDateTime(dt.d, date, time);
return dt;
}
-#undef MASSAGEADJUSTEDDATETIME
/*!
Returns a QDateTime object containing a datetime \a s seconds
@@ -3834,12 +4014,26 @@ QDateTime QDateTime::addMSecs(qint64 msecs) const
return QDateTime();
QDateTime dt(*this);
- if (d->m_spec == Qt::LocalTime || d->m_spec == Qt::TimeZone)
+ auto spec = getSpec(d);
+ if (spec == Qt::LocalTime || spec == Qt::TimeZone) {
// Convert to real UTC first in case crosses DST transition
- dt.setMSecsSinceEpoch(d->toMSecsSinceEpoch() + msecs);
- else
+ dt.setMSecsSinceEpoch(toMSecsSinceEpoch() + msecs);
+ } else {
// No need to convert, just add on
- dt.d->m_msecs = dt.d->m_msecs + msecs;
+ if (d.isShort()) {
+ // need to check if we need to enlarge first
+ msecs += dt.d.data.msecs;
+ if (msecsCanBeSmall(msecs)) {
+ dt.d.data.msecs = qintptr(msecs);
+ } else {
+ dt.d.detach();
+ dt.d->m_msecs = msecs;
+ }
+ } else {
+ dt.d.detach();
+ dt.d->m_msecs += msecs;
+ }
+ }
return dt;
}
@@ -3905,7 +4099,7 @@ qint64 QDateTime::msecsTo(const QDateTime &other) const
if (!isValid() || !other.isValid())
return 0;
- return other.d->toMSecsSinceEpoch() - d->toMSecsSinceEpoch();
+ return other.toMSecsSinceEpoch() - toMSecsSinceEpoch();
}
/*!
@@ -3928,7 +4122,7 @@ qint64 QDateTime::msecsTo(const QDateTime &other) const
QDateTime QDateTime::toTimeSpec(Qt::TimeSpec spec) const
{
- if (d->m_spec == spec && (spec == Qt::UTC || spec == Qt::LocalTime))
+ if (getSpec(d) == spec && (spec == Qt::UTC || spec == Qt::LocalTime))
return *this;
if (!isValid()) {
@@ -3937,7 +4131,7 @@ QDateTime QDateTime::toTimeSpec(Qt::TimeSpec spec) const
return ret;
}
- return fromMSecsSinceEpoch(d->toMSecsSinceEpoch(), spec, 0);
+ return fromMSecsSinceEpoch(toMSecsSinceEpoch(), spec, 0);
}
/*!
@@ -3955,7 +4149,8 @@ QDateTime QDateTime::toTimeSpec(Qt::TimeSpec spec) const
QDateTime QDateTime::toOffsetFromUtc(int offsetSeconds) const
{
- if (d->m_spec == Qt::OffsetFromUTC && d->m_offsetFromUtc == offsetSeconds)
+ if (getSpec(d) == Qt::OffsetFromUTC
+ && d->m_offsetFromUtc == offsetSeconds)
return *this;
if (!isValid()) {
@@ -3964,7 +4159,7 @@ QDateTime QDateTime::toOffsetFromUtc(int offsetSeconds) const
return ret;
}
- return fromMSecsSinceEpoch(d->toMSecsSinceEpoch(), Qt::OffsetFromUTC, offsetSeconds);
+ return fromMSecsSinceEpoch(toMSecsSinceEpoch(), Qt::OffsetFromUTC, offsetSeconds);
}
#ifndef QT_BOOTSTRAPPED
@@ -3978,7 +4173,7 @@ QDateTime QDateTime::toOffsetFromUtc(int offsetSeconds) const
QDateTime QDateTime::toTimeZone(const QTimeZone &timeZone) const
{
- if (d->m_spec == Qt::TimeZone && d->m_timeZone == timeZone)
+ if (getSpec(d) == Qt::TimeZone && d->m_timeZone == timeZone)
return *this;
if (!isValid()) {
@@ -3987,7 +4182,7 @@ QDateTime QDateTime::toTimeZone(const QTimeZone &timeZone) const
return ret;
}
- return fromMSecsSinceEpoch(d->toMSecsSinceEpoch(), timeZone);
+ return fromMSecsSinceEpoch(toMSecsSinceEpoch(), timeZone);
}
#endif // QT_BOOTSTRAPPED
@@ -4000,10 +4195,9 @@ QDateTime QDateTime::toTimeZone(const QTimeZone &timeZone) const
bool QDateTime::operator==(const QDateTime &other) const
{
- if (d->m_spec == Qt::LocalTime
- && other.d->m_spec == Qt::LocalTime
- && d->m_status == other.d->m_status) {
- return (d->m_msecs == other.d->m_msecs);
+ if (getSpec(d) == Qt::LocalTime
+ && getStatus(d) == getStatus(other.d)) {
+ return getMSecs(d) == getMSecs(other.d);
}
// Convert to UTC and compare
return (toMSecsSinceEpoch() == other.toMSecsSinceEpoch());
@@ -4028,10 +4222,9 @@ bool QDateTime::operator==(const QDateTime &other) const
bool QDateTime::operator<(const QDateTime &other) const
{
- if (d->m_spec == Qt::LocalTime
- && other.d->m_spec == Qt::LocalTime
- && d->m_status == other.d->m_status) {
- return (d->m_msecs < other.d->m_msecs);
+ if (getSpec(d) == Qt::LocalTime
+ && getStatus(d) == getStatus(other.d)) {
+ return getMSecs(d) < getMSecs(other.d);
}
// Convert to UTC and compare
return (toMSecsSinceEpoch() < other.toMSecsSinceEpoch());
@@ -4086,6 +4279,16 @@ bool QDateTime::operator<(const QDateTime &other) const
\sa currentDateTime(), currentDateTimeUtc(), toTime_t(), toTimeSpec()
*/
+/*!
+ \fn qint64 QDateTime::currentSecsSinceEpoch()
+ \since 5.8
+
+ Returns the number of seconds since 1970-01-01T00:00:00 Universal
+ Coordinated Time.
+
+ \sa currentMSecsSinceEpoch()
+*/
+
#if defined(Q_OS_WIN)
static inline uint msecsFromDecomposed(int hour, int minute, int sec, int msec = 0)
{
@@ -4109,9 +4312,6 @@ QTime QTime::currentTime()
memset(&st, 0, sizeof(SYSTEMTIME));
GetLocalTime(&st);
ct.setHMS(st.wHour, st.wMinute, st.wSecond, st.wMilliseconds);
-#if defined(Q_OS_WINCE)
- ct.startTick = GetTickCount() % MSECS_PER_DAY;
-#endif
return ct;
}
@@ -4150,6 +4350,17 @@ qint64 QDateTime::currentMSecsSinceEpoch() Q_DECL_NOTHROW
- julianDayFromDate(1970, 1, 1)) * Q_INT64_C(86400000);
}
+qint64 QDateTime::currentSecsSinceEpoch() Q_DECL_NOTHROW
+{
+ SYSTEMTIME st;
+ memset(&st, 0, sizeof(SYSTEMTIME));
+ GetSystemTime(&st);
+
+ return st.wHour * SECS_PER_HOUR + st.wMinute * SECS_PER_MIN + st.wSecond +
+ qint64(julianDayFromDate(st.wYear, st.wMonth, st.wDay)
+ - julianDayFromDate(1970, 1, 1)) * Q_INT64_C(86400);
+}
+
#elif defined(Q_OS_UNIX)
QDate QDate::currentDate()
{
@@ -4180,51 +4391,29 @@ qint64 QDateTime::currentMSecsSinceEpoch() Q_DECL_NOTHROW
return qint64(tv.tv_sec) * Q_INT64_C(1000) + tv.tv_usec / 1000;
}
+qint64 QDateTime::currentSecsSinceEpoch() Q_DECL_NOTHROW
+{
+ struct timeval tv;
+ gettimeofday(&tv, 0);
+ return qint64(tv.tv_sec);
+}
#else
#error "What system is this?"
#endif
-/*! \fn QDateTime QDateTime::fromCFDate(CFDateRef date)
- \since 5.5
-
- Constructs a new QDateTime containing a copy of the CFDate \a date.
-
- \sa toCFDate()
-*/
-
-/*! \fn CFDateRef QDateTime::toCFDate() const
- \since 5.5
-
- Creates a CFDate from a QDateTime. The caller owns the CFDate object
- and is responsible for releasing it.
-
- \sa fromCFDate()
-*/
-
-/*! \fn QDateTime QDateTime::fromNSDate(const NSDate *date)
- \since 5.5
-
- Constructs a new QDateTime containing a copy of the NSDate \a date.
-
- \sa toNSDate()
-*/
-
-/*! \fn NSDate QDateTime::toNSDate() const
- \since 5.5
-
- Creates an NSDate from a QDateTime. The NSDate object is autoreleased.
-
- \sa fromNSDate()
-*/
-
+#if QT_DEPRECATED_SINCE(5, 8)
/*!
\since 4.2
+ \deprecated
Returns a datetime whose date and time are the number of \a seconds
that have passed since 1970-01-01T00:00:00, Coordinated Universal
Time (Qt::UTC) and converted to Qt::LocalTime. On systems that do not
support time zones, the time will be set as if local time were Qt::UTC.
+ \note This function is deprecated. Please use fromSecsSinceEpoch() in new
+ code.
+
\sa toTime_t(), setTime_t()
*/
QDateTime QDateTime::fromTime_t(uint seconds)
@@ -4234,6 +4423,7 @@ QDateTime QDateTime::fromTime_t(uint seconds)
/*!
\since 5.2
+ \deprecated
Returns a datetime whose date and time are the number of \a seconds
that have passed since 1970-01-01T00:00:00, Coordinated Universal
@@ -4243,6 +4433,9 @@ QDateTime QDateTime::fromTime_t(uint seconds)
ignored. If the \a spec is Qt::OffsetFromUTC and the \a offsetSeconds is 0
then the spec will be set to Qt::UTC, i.e. an offset of 0 seconds.
+ \note This function is deprecated. Please use fromSecsSinceEpoch() in new
+ code.
+
\sa toTime_t(), setTime_t()
*/
QDateTime QDateTime::fromTime_t(uint seconds, Qt::TimeSpec spec, int offsetSeconds)
@@ -4253,11 +4446,15 @@ QDateTime QDateTime::fromTime_t(uint seconds, Qt::TimeSpec spec, int offsetSecon
#ifndef QT_BOOTSTRAPPED
/*!
\since 5.2
+ \deprecated
Returns a datetime whose date and time are the number of \a seconds
that have passed since 1970-01-01T00:00:00, Coordinated Universal
Time (Qt::UTC) and with the given \a timeZone.
+ \note This function is deprecated. Please use fromSecsSinceEpoch() in new
+ code.
+
\sa toTime_t(), setTime_t()
*/
QDateTime QDateTime::fromTime_t(uint seconds, const QTimeZone &timeZone)
@@ -4265,6 +4462,7 @@ QDateTime QDateTime::fromTime_t(uint seconds, const QTimeZone &timeZone)
return fromMSecsSinceEpoch((qint64)seconds * 1000, timeZone);
}
#endif
+#endif // QT_DEPRECATED_SINCE(5, 8)
/*!
\since 4.7
@@ -4278,7 +4476,7 @@ QDateTime QDateTime::fromTime_t(uint seconds, const QTimeZone &timeZone)
range of QDateTime, both negative and positive. The behavior of this
function is undefined for those values.
- \sa toTime_t(), setTime_t()
+ \sa toMSecsSinceEpoch(), setMSecsSinceEpoch()
*/
QDateTime QDateTime::fromMSecsSinceEpoch(qint64 msecs)
{
@@ -4303,16 +4501,41 @@ QDateTime QDateTime::fromMSecsSinceEpoch(qint64 msecs)
If \a spec is Qt::TimeZone then the spec will be set to Qt::LocalTime,
i.e. the current system time zone.
- \sa fromTime_t()
+ \sa toMSecsSinceEpoch(), setMSecsSinceEpoch()
*/
QDateTime QDateTime::fromMSecsSinceEpoch(qint64 msecs, Qt::TimeSpec spec, int offsetSeconds)
{
QDateTime dt;
- dt.d->setTimeSpec(spec, offsetSeconds);
+ QT_PREPEND_NAMESPACE(setTimeSpec(dt.d, spec, offsetSeconds));
dt.setMSecsSinceEpoch(msecs);
return dt;
}
+/*!
+ \since 5.8
+
+ Returns a datetime whose date and time are the number of seconds \a secs
+ that have passed since 1970-01-01T00:00:00.000, Coordinated Universal
+ Time (Qt::UTC) and converted to the given \a spec.
+
+ Note that there are possible values for \a secs that lie outside the valid
+ range of QDateTime, both negative and positive. The behavior of this
+ function is undefined for those values.
+
+ If the \a spec is not Qt::OffsetFromUTC then the \a offsetSeconds will be
+ ignored. If the \a spec is Qt::OffsetFromUTC and the \a offsetSeconds is 0
+ then the spec will be set to Qt::UTC, i.e. an offset of 0 seconds.
+
+ If \a spec is Qt::TimeZone then the spec will be set to Qt::LocalTime,
+ i.e. the current system time zone.
+
+ \sa toSecsSinceEpoch(), setSecsSinceEpoch()
+*/
+QDateTime QDateTime::fromSecsSinceEpoch(qint64 secs, Qt::TimeSpec spec, int offsetSeconds)
+{
+ return fromMSecsSinceEpoch(secs * 1000, spec, offsetSeconds);
+}
+
#ifndef QT_BOOTSTRAPPED
/*!
\since 5.2
@@ -4321,7 +4544,7 @@ QDateTime QDateTime::fromMSecsSinceEpoch(qint64 msecs, Qt::TimeSpec spec, int of
that have passed since 1970-01-01T00:00:00.000, Coordinated Universal
Time (Qt::UTC) and with the given \a timeZone.
- \sa fromTime_t()
+ \sa fromSecsSinceEpoch()
*/
QDateTime QDateTime::fromMSecsSinceEpoch(qint64 msecs, const QTimeZone &timeZone)
{
@@ -4330,6 +4553,20 @@ QDateTime QDateTime::fromMSecsSinceEpoch(qint64 msecs, const QTimeZone &timeZone
dt.setMSecsSinceEpoch(msecs);
return dt;
}
+
+/*!
+ \since 5.8
+
+ Returns a datetime whose date and time are the number of seconds \a secs
+ that have passed since 1970-01-01T00:00:00.000, Coordinated Universal
+ Time (Qt::UTC) and with the given \a timeZone.
+
+ \sa fromMSecsSinceEpoch()
+*/
+QDateTime QDateTime::fromSecsSinceEpoch(qint64 secs, const QTimeZone &timeZone)
+{
+ return fromMSecsSinceEpoch(secs * 1000, timeZone);
+}
#endif
#if QT_DEPRECATED_SINCE(5, 2)
@@ -4825,7 +5062,7 @@ QDataStream &operator<<(QDataStream &out, const QDateTime &dateTime)
if (out.version() >= QDataStream::Qt_5_2) {
// In 5.2 we switched to using Qt::TimeSpec and added offset support
- dateAndTime = dateTime.d->getDateTime();
+ dateAndTime = getDateTime(dateTime.d);
out << dateAndTime << qint8(dateTime.timeSpec());
if (dateTime.timeSpec() == Qt::OffsetFromUTC)
out << qint32(dateTime.offsetFromUtc());
@@ -4840,13 +5077,13 @@ QDataStream &operator<<(QDataStream &out, const QDateTime &dateTime)
// This approach is wrong and should not be used again; it breaks
// the guarantee that a deserialised local datetime is the same time
// of day, regardless of which timezone it was serialised in.
- dateAndTime = (dateTime.isValid() ? dateTime.toUTC() : dateTime).d->getDateTime();
+ dateAndTime = getDateTime((dateTime.isValid() ? dateTime.toUTC() : dateTime).d);
out << dateAndTime << qint8(dateTime.timeSpec());
} else if (out.version() >= QDataStream::Qt_4_0) {
// From 4.0 to 5.1 (except 5.0) we used QDateTimePrivate::Spec
- dateAndTime = dateTime.d->getDateTime();
+ dateAndTime = getDateTime(dateTime.d);
out << dateAndTime;
switch (dateTime.timeSpec()) {
case Qt::UTC:
@@ -4866,7 +5103,7 @@ QDataStream &operator<<(QDataStream &out, const QDateTime &dateTime)
} else { // version < QDataStream::Qt_4_0
// Before 4.0 there was no TimeSpec, only Qt::LocalTime was supported
- dateAndTime = dateTime.d->getDateTime();
+ dateAndTime = getDateTime(dateTime.d);
out << dateAndTime;
}
diff --git a/src/corelib/tools/qdatetime.h b/src/corelib/tools/qdatetime.h
index f292a97db1..ebf9b45570 100644
--- a/src/corelib/tools/qdatetime.h
+++ b/src/corelib/tools/qdatetime.h
@@ -1,6 +1,7 @@
/****************************************************************************
**
** Copyright (C) 2016 The Qt Company Ltd.
+** Copyright (C) 2016 Intel Corporation.
** Contact: https://www.qt.io/licensing/
**
** This file is part of the QtCore module of the Qt Toolkit.
@@ -46,11 +47,9 @@
#include <limits>
-#ifdef Q_OS_MAC
+#if defined(Q_OS_DARWIN) || defined(Q_QDOC)
Q_FORWARD_DECLARE_CF_TYPE(CFDate);
-# ifdef __OBJC__
Q_FORWARD_DECLARE_OBJC_CLASS(NSDate);
-# endif
#endif
QT_BEGIN_NAMESPACE
@@ -148,15 +147,9 @@ Q_DECLARE_TYPEINFO(QDate, Q_MOVABLE_TYPE);
class Q_CORE_EXPORT QTime
{
explicit Q_DECL_CONSTEXPR QTime(int ms) : mds(ms)
-#if defined(Q_OS_WINCE)
- , startTick(NullTime)
-#endif
{}
public:
Q_DECL_CONSTEXPR QTime(): mds(NullTime)
-#if defined(Q_OS_WINCE)
- , startTick(NullTime)
-#endif
{}
QTime(int h, int m, int s = 0, int ms = 0);
@@ -202,9 +195,6 @@ private:
enum TimeFlag { NullTime = -1 };
Q_DECL_CONSTEXPR inline int ds() const { return mds == -1 ? 0 : mds; }
int mds;
-#if defined(Q_OS_WINCE)
- int startTick;
-#endif
friend class QDateTime;
friend class QDateTimePrivate;
@@ -219,8 +209,46 @@ class QDateTimePrivate;
class Q_CORE_EXPORT QDateTime
{
+ // ### Qt 6: revisit the optimization
+ struct ShortData {
+#if Q_BYTE_ORDER == Q_LITTLE_ENDIAN
+ quintptr status : 8;
+#endif
+ // note: this is only 24 bits on 32-bit systems...
+ qintptr msecs : sizeof(void *) * 8 - 8;
+
+#if Q_BYTE_ORDER == Q_BIG_ENDIAN
+ quintptr status : 8;
+#endif
+ };
+
+ union Data {
+ enum {
+ // To be of any use, we need at least 60 years around 1970, which
+ // is 1,893,456,000,000 ms. That requires 41 bits to store, plus
+ // the sign bit. With the status byte, the minimum size is 50 bits.
+ CanBeSmall = sizeof(ShortData) * 8 > 50
+ };
+
+ Data();
+ Data(Qt::TimeSpec);
+ Data(const Data &other);
+ Data(Data &&other);
+ Data &operator=(const Data &other);
+ ~Data();
+
+ bool isShort() const;
+ void detach();
+
+ const QDateTimePrivate *operator->() const;
+ QDateTimePrivate *operator->();
+
+ QDateTimePrivate *d;
+ ShortData data;
+ };
+
public:
- QDateTime();
+ QDateTime() Q_DECL_NOEXCEPT_EXPR(Data::CanBeSmall);
explicit QDateTime(const QDate &);
QDateTime(const QDate &, const QTime &, Qt::TimeSpec spec = Qt::LocalTime);
// ### Qt 6: Merge with above with default offsetSeconds = 0
@@ -228,15 +256,16 @@ public:
#ifndef QT_BOOTSTRAPPED
QDateTime(const QDate &date, const QTime &time, const QTimeZone &timeZone);
#endif // QT_BOOTSTRAPPED
- QDateTime(const QDateTime &other);
+ QDateTime(const QDateTime &other) Q_DECL_NOTHROW;
+ QDateTime(QDateTime &&other) Q_DECL_NOTHROW;
~QDateTime();
#ifdef Q_COMPILER_RVALUE_REFS
QDateTime &operator=(QDateTime &&other) Q_DECL_NOTHROW { swap(other); return *this; }
#endif
- QDateTime &operator=(const QDateTime &other);
+ QDateTime &operator=(const QDateTime &other) Q_DECL_NOTHROW;
- void swap(QDateTime &other) Q_DECL_NOTHROW { qSwap(d, other.d); }
+ void swap(QDateTime &other) Q_DECL_NOTHROW { qSwap(d.d, other.d.d); }
bool isNull() const;
bool isValid() const;
@@ -252,8 +281,7 @@ public:
bool isDaylightTime() const;
qint64 toMSecsSinceEpoch() const;
- // ### Qt 6: use quint64 instead of uint
- uint toTime_t() const;
+ qint64 toSecsSinceEpoch() const;
void setDate(const QDate &date);
void setTime(const QTime &time);
@@ -263,8 +291,7 @@ public:
void setTimeZone(const QTimeZone &toZone);
#endif // QT_BOOTSTRAPPED
void setMSecsSinceEpoch(qint64 msecs);
- // ### Qt 6: use quint64 instead of uint
- void setTime_t(uint secsSince1Jan1970UTC);
+ void setSecsSinceEpoch(qint64 secs);
#ifndef QT_NO_DATESTRING
QString toString(Qt::DateFormat f = Qt::TextDate) const;
@@ -306,38 +333,40 @@ public:
static QDateTime fromString(const QString &s, Qt::DateFormat f = Qt::TextDate);
static QDateTime fromString(const QString &s, const QString &format);
#endif
- // ### Qt 6: use quint64 instead of uint
+
+#if QT_DEPRECATED_SINCE(5, 8)
+ uint toTime_t() const;
+ void setTime_t(uint secsSince1Jan1970UTC);
static QDateTime fromTime_t(uint secsSince1Jan1970UTC);
- // ### Qt 6: Merge with above with default spec = Qt::LocalTime
static QDateTime fromTime_t(uint secsSince1Jan1970UTC, Qt::TimeSpec spec,
int offsetFromUtc = 0);
-#ifndef QT_BOOTSTRAPPED
static QDateTime fromTime_t(uint secsSince1Jan1970UTC, const QTimeZone &timeZone);
#endif
+
static QDateTime fromMSecsSinceEpoch(qint64 msecs);
// ### Qt 6: Merge with above with default spec = Qt::LocalTime
static QDateTime fromMSecsSinceEpoch(qint64 msecs, Qt::TimeSpec spec, int offsetFromUtc = 0);
+ static QDateTime fromSecsSinceEpoch(qint64 secs, Qt::TimeSpec spe = Qt::LocalTime, int offsetFromUtc = 0);
+
#ifndef QT_BOOTSTRAPPED
static QDateTime fromMSecsSinceEpoch(qint64 msecs, const QTimeZone &timeZone);
+ static QDateTime fromSecsSinceEpoch(qint64 secs, const QTimeZone &timeZone);
#endif
+
static qint64 currentMSecsSinceEpoch() Q_DECL_NOTHROW;
+ static qint64 currentSecsSinceEpoch() Q_DECL_NOTHROW;
-#if defined(Q_OS_MAC) || defined(Q_QDOC)
+#if defined(Q_OS_DARWIN) || defined(Q_QDOC)
static QDateTime fromCFDate(CFDateRef date);
CFDateRef toCFDate() const Q_DECL_CF_RETURNS_RETAINED;
-# if defined(__OBJC__) || defined(Q_QDOC)
static QDateTime fromNSDate(const NSDate *date);
NSDate *toNSDate() const Q_DECL_NS_RETURNS_AUTORELEASED;
-# endif
#endif
private:
friend class QDateTimePrivate;
- // ### Qt6: Using a private here has high impact on runtime
- // on users such as QFileInfo. In Qt 6, the data members
- // should be inlined.
- QSharedDataPointer<QDateTimePrivate> d;
+ Data d;
#ifndef QT_NO_DATASTREAM
friend Q_CORE_EXPORT QDataStream &operator<<(QDataStream &, const QDateTime &);
diff --git a/src/corelib/tools/qdatetime_mac.mm b/src/corelib/tools/qdatetime_mac.mm
deleted file mode 100644
index d61ea28636..0000000000
--- a/src/corelib/tools/qdatetime_mac.mm
+++ /dev/null
@@ -1,74 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Copyright (C) 2014 Petroules Corporation.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtCore module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include "qdatetime.h"
-
-#import <Foundation/Foundation.h>
-
-QT_BEGIN_NAMESPACE
-
-QDateTime QDateTime::fromCFDate(CFDateRef date)
-{
- if (!date)
- return QDateTime();
- return QDateTime::fromMSecsSinceEpoch(static_cast<qint64>((CFDateGetAbsoluteTime(date)
- + kCFAbsoluteTimeIntervalSince1970) * 1000));
-}
-
-CFDateRef QDateTime::toCFDate() const
-{
- return CFDateCreate(kCFAllocatorDefault, (static_cast<CFAbsoluteTime>(toMSecsSinceEpoch())
- / 1000) - kCFAbsoluteTimeIntervalSince1970);
-}
-
-QDateTime QDateTime::fromNSDate(const NSDate *date)
-{
- if (!date)
- return QDateTime();
- return QDateTime::fromMSecsSinceEpoch(static_cast<qint64>([date timeIntervalSince1970] * 1000));
-}
-
-NSDate *QDateTime::toNSDate() const
-{
- return [NSDate
- dateWithTimeIntervalSince1970:static_cast<NSTimeInterval>(toMSecsSinceEpoch()) / 1000];
-}
-
-QT_END_NAMESPACE
diff --git a/src/corelib/tools/qdatetime_p.h b/src/corelib/tools/qdatetime_p.h
index 104cbccbd4..38a084b257 100644
--- a/src/corelib/tools/qdatetime_p.h
+++ b/src/corelib/tools/qdatetime_p.h
@@ -1,6 +1,7 @@
/****************************************************************************
**
** Copyright (C) 2016 The Qt Company Ltd.
+** Copyright (C) 2016 Intel Corporation.
** Contact: https://www.qt.io/licensing/
**
** This file is part of the QtCore module of the Qt Toolkit.
@@ -51,6 +52,7 @@
// We mean it.
//
+#include <QtCore/private/qglobal_p.h>
#include "qplatformdefs.h"
#include "QtCore/qatomic.h"
#include "QtCore/qdatetime.h"
@@ -60,9 +62,13 @@
QT_BEGIN_NAMESPACE
-class QDateTimePrivate : public QSharedData
+class QDateTimePrivate
{
public:
+ // forward the declarations from QDateTime (this makes them public)
+ typedef QDateTime::ShortData QDateTimeShortData;
+ typedef QDateTime::Data QDateTimeData;
+
// Never change or delete this enum, it is required for backwards compatible
// serialization of QDateTime before 5.2, so is essentially public API
enum Spec {
@@ -76,7 +82,6 @@ public:
// Daylight Time Status
enum DaylightStatus {
- NoDaylightTime = -2,
UnknownDaylightTime = -1,
StandardTime = 0,
DaylightTime = 1
@@ -84,62 +89,46 @@ public:
// Status of date/time
enum StatusFlag {
- NullDate = 0x01,
- NullTime = 0x02,
- ValidDate = 0x04, // just the date field
- ValidTime = 0x08, // just the time field
- ValidDateTime = 0x10, // the whole object (including timezone)
+ ShortData = 0x01,
+
+ ValidDate = 0x02,
+ ValidTime = 0x04,
+ ValidDateTime = 0x08,
+
+ TimeSpecMask = 0x30,
+
SetToStandardTime = 0x40,
SetToDaylightTime = 0x80
};
Q_DECLARE_FLAGS(StatusFlags, StatusFlag)
+ enum {
+ TimeSpecShift = 4,
+ ValidityMask = ValidDate | ValidTime | ValidDateTime,
+ DaylightMask = SetToStandardTime | SetToDaylightTime
+ };
+
QDateTimePrivate() : m_msecs(0),
- m_spec(Qt::LocalTime),
+ m_status(StatusFlag(Qt::LocalTime << TimeSpecShift)),
m_offsetFromUtc(0),
- m_status(NullDate | NullTime)
- {}
+ ref(0)
+ {
+ }
- QDateTimePrivate(const QDate &toDate, const QTime &toTime, Qt::TimeSpec toSpec,
- int offsetSeconds);
+ static QDateTime::Data create(const QDate &toDate, const QTime &toTime, Qt::TimeSpec toSpec,
+ int offsetSeconds);
#ifndef QT_BOOTSTRAPPED
- QDateTimePrivate(const QDate &toDate, const QTime &toTime, const QTimeZone & timeZone);
+ static QDateTime::Data create(const QDate &toDate, const QTime &toTime, const QTimeZone & timeZone);
#endif // QT_BOOTSTRAPPED
- // ### XXX: when the tooling situation improves, look at fixing the padding.
- // 4 bytes padding
-
qint64 m_msecs;
- Qt::TimeSpec m_spec;
+ StatusFlags m_status;
int m_offsetFromUtc;
+ mutable QAtomicInt ref;
#ifndef QT_BOOTSTRAPPED
QTimeZone m_timeZone;
#endif // QT_BOOTSTRAPPED
- StatusFlags m_status;
-
- void setTimeSpec(Qt::TimeSpec spec, int offsetSeconds);
- void setDateTime(const QDate &date, const QTime &time);
- QPair<QDate, QTime> getDateTime() const;
-
- void setDaylightStatus(DaylightStatus status);
- DaylightStatus daylightStatus() const;
-
- // Returns msecs since epoch, assumes offset value is current
- inline qint64 toMSecsSinceEpoch() const;
-
- void checkValidDateTime();
- void refreshDateTime();
-
- // Get/set date and time status
- inline bool isNullDate() const { return m_status & NullDate; }
- inline bool isNullTime() const { return m_status & NullTime; }
- inline bool isValidDate() const { return m_status & ValidDate; }
- inline bool isValidTime() const { return m_status & ValidTime; }
- inline bool isValidDateTime() const { return m_status & ValidDateTime; }
- inline void setValidDateTime() { m_status |= ValidDateTime; }
- inline void clearValidDateTime() { m_status &= ~ValidDateTime; }
- inline void clearSetToDaylightStatus() { m_status &= ~(SetToStandardTime | SetToDaylightTime); }
#ifndef QT_BOOTSTRAPPED
static qint64 zoneMSecsToEpochMSecs(qint64 msecs, const QTimeZone &zone,
diff --git a/src/corelib/tools/qdatetimeparser_p.h b/src/corelib/tools/qdatetimeparser_p.h
index 01a2f20802..6f381965a9 100644
--- a/src/corelib/tools/qdatetimeparser_p.h
+++ b/src/corelib/tools/qdatetimeparser_p.h
@@ -51,6 +51,7 @@
// We mean it.
//
+#include <QtCore/private/qglobal_p.h>
#include "qplatformdefs.h"
#include "QtCore/qatomic.h"
#include "QtCore/qdatetime.h"
diff --git a/src/corelib/tools/qelapsedtimer.cpp b/src/corelib/tools/qelapsedtimer.cpp
deleted file mode 100644
index 2eabb4c3a3..0000000000
--- a/src/corelib/tools/qelapsedtimer.cpp
+++ /dev/null
@@ -1,267 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtCore module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include "qelapsedtimer.h"
-
-QT_BEGIN_NAMESPACE
-
-/*!
- \class QElapsedTimer
- \inmodule QtCore
- \brief The QElapsedTimer class provides a fast way to calculate elapsed times.
- \since 4.7
-
- \reentrant
- \ingroup tools
-
- The QElapsedTimer class is usually used to quickly calculate how much
- time has elapsed between two events. Its API is similar to that of QTime,
- so code that was using that can be ported quickly to the new class.
-
- However, unlike QTime, QElapsedTimer tries to use monotonic clocks if
- possible. This means it's not possible to convert QElapsedTimer objects
- to a human-readable time.
-
- The typical use-case for the class is to determine how much time was
- spent in a slow operation. The simplest example of such a case is for
- debugging purposes, as in the following example:
-
- \snippet qelapsedtimer/main.cpp 0
-
- In this example, the timer is started by a call to start() and the
- elapsed timer is calculated by the elapsed() function.
-
- The time elapsed can also be used to recalculate the time available for
- another operation, after the first one is complete. This is useful when
- the execution must complete within a certain time period, but several
- steps are needed. The \tt{waitFor}-type functions in QIODevice and its
- subclasses are good examples of such need. In that case, the code could
- be as follows:
-
- \snippet qelapsedtimer/main.cpp 1
-
- Another use-case is to execute a certain operation for a specific
- timeslice. For this, QElapsedTimer provides the hasExpired() convenience
- function, which can be used to determine if a certain number of
- milliseconds has already elapsed:
-
- \snippet qelapsedtimer/main.cpp 2
-
- \section1 Reference Clocks
-
- QElapsedTimer will use the platform's monotonic reference clock in all
- platforms that support it (see QElapsedTimer::isMonotonic()). This has
- the added benefit that QElapsedTimer is immune to time adjustments, such
- as the user correcting the time. Also unlike QTime, QElapsedTimer is
- immune to changes in the timezone settings, such as daylight-saving
- periods.
-
- On the other hand, this means QElapsedTimer values can only be compared
- with other values that use the same reference. This is especially true if
- the time since the reference is extracted from the QElapsedTimer object
- (QElapsedTimer::msecsSinceReference()) and serialised. These values
- should never be exchanged across the network or saved to disk, since
- there's no telling whether the computer node receiving the data is the
- same as the one originating it or if it has rebooted since.
-
- It is, however, possible to exchange the value with other processes
- running on the same machine, provided that they also use the same
- reference clock. QElapsedTimer will always use the same clock, so it's
- safe to compare with the value coming from another process in the same
- machine. If comparing to values produced by other APIs, you should check
- that the clock used is the same as QElapsedTimer (see
- QElapsedTimer::clockType()).
-
- \section2 32-bit overflows
-
- Some of the clocks used by QElapsedTimer have a limited range and may
- overflow after hitting the upper limit (usually 32-bit). QElapsedTimer
- deals with this overflow issue and presents a consistent timing. However,
- when extracting the time since reference from QElapsedTimer, two
- different processes in the same machine may have different understanding
- of how much time has actually elapsed.
-
- The information on which clocks types may overflow and how to remedy that
- issue is documented along with the clock types.
-
- \sa QTime, QTimer
-*/
-
-/*!
- \enum QElapsedTimer::ClockType
-
- This enum contains the different clock types that QElapsedTimer may use.
-
- QElapsedTimer will always use the same clock type in a particular
- machine, so this value will not change during the lifetime of a program.
- It is provided so that QElapsedTimer can be used with other non-Qt
- implementations, to guarantee that the same reference clock is being
- used.
-
- \value SystemTime The human-readable system time. This clock is not monotonic.
- \value MonotonicClock The system's monotonic clock, usually found in Unix systems. This clock is monotonic and does not overflow.
- \value TickCounter The system's tick counter, used on Windows systems. This clock may overflow.
- \value MachAbsoluteTime The Mach kernel's absolute time (OS X and iOS). This clock is monotonic and does not overflow.
- \value PerformanceCounter The high-resolution performance counter provided by Windows. This clock is monotonic and does not overflow.
-
- \section2 SystemTime
-
- The system time clock is purely the real time, expressed in milliseconds
- since Jan 1, 1970 at 0:00 UTC. It's equivalent to the value returned by
- the C and POSIX \tt{time} function, with the milliseconds added. This
- clock type is currently only used on Unix systems that do not support
- monotonic clocks (see below).
-
- This is the only non-monotonic clock that QElapsedTimer may use.
-
- \section2 MonotonicClock
-
- This is the system's monotonic clock, expressed in milliseconds since an
- arbitrary point in the past. This clock type is used on Unix systems
- which support POSIX monotonic clocks (\tt{_POSIX_MONOTONIC_CLOCK}).
-
- This clock does not overflow.
-
- \section2 TickCounter
-
- The tick counter clock type is based on the system's or the processor's
- tick counter, multiplied by the duration of a tick. This clock type is
- used on Windows platforms. If the high-precision performance
- counter is available on Windows, the \tt{PerformanceCounter} clock type
- is used instead.
-
- The TickCounter clock type is the only clock type that may overflow.
- Windows Vista and Windows Server 2008 support the extended 64-bit tick
- counter, which allows avoiding the overflow.
-
- On Windows systems, the clock overflows after 2^32 milliseconds, which
- corresponds to roughly 49.7 days. This means two processes' reckoning of
- the time since the reference may be different by multiples of 2^32
- milliseconds. When comparing such values, it's recommended that the high
- 32 bits of the millisecond count be masked off.
-
- \section2 MachAbsoluteTime
-
- This clock type is based on the absolute time presented by Mach kernels,
- such as that found on OS X. This clock type is presented separately
- from MonotonicClock since OS X and iOS are also Unix systems and may support
- a POSIX monotonic clock with values differing from the Mach absolute
- time.
-
- This clock is monotonic and does not overflow.
-
- \section2 PerformanceCounter
-
- This clock uses the Windows functions \tt{QueryPerformanceCounter} and
- \tt{QueryPerformanceFrequency} to access the system's high-precision
- performance counter. Since this counter may not be available on all
- systems, QElapsedTimer will fall back to the \tt{TickCounter} clock
- automatically, if this clock cannot be used.
-
- This clock is monotonic and does not overflow.
-
- \sa clockType(), isMonotonic()
-*/
-
-/*!
- \fn QElapsedTimer::QElapsedTimer()
- \since 5.4
-
- Constructs an invalid QElapsedTimer. A timer becomes valid once it has been
- started.
-
- \sa isValid(), start()
-*/
-
-
-/*!
- \fn bool QElapsedTimer::operator ==(const QElapsedTimer &other) const
-
- Returns \c true if this object and \a other contain the same time.
-*/
-
-/*!
- \fn bool QElapsedTimer::operator !=(const QElapsedTimer &other) const
-
- Returns \c true if this object and \a other contain different times.
-*/
-
-static const qint64 invalidData = Q_INT64_C(0x8000000000000000);
-
-/*!
- Marks this QElapsedTimer object as invalid.
-
- An invalid object can be checked with isValid(). Calculations of timer
- elapsed since invalid data are undefined and will likely produce bizarre
- results.
-
- \sa isValid(), start(), restart()
-*/
-void QElapsedTimer::invalidate() Q_DECL_NOTHROW
-{
- t1 = t2 = invalidData;
-}
-
-/*!
- Returns \c false if the timer has never been started or invalidated by a
- call to invalidate().
-
- \sa invalidate(), start(), restart()
-*/
-bool QElapsedTimer::isValid() const Q_DECL_NOTHROW
-{
- return t1 != invalidData && t2 != invalidData;
-}
-
-/*!
- Returns \c true if this QElapsedTimer has already expired by \a timeout
- milliseconds (that is, more than \a timeout milliseconds have elapsed).
- The value of \a timeout can be -1 to indicate that this timer does not
- expire, in which case this function will always return false.
-
- \sa elapsed()
-*/
-bool QElapsedTimer::hasExpired(qint64 timeout) const Q_DECL_NOTHROW
-{
- // if timeout is -1, quint64(timeout) is LLINT_MAX, so this will be
- // considered as never expired
- return quint64(elapsed()) > quint64(timeout);
-}
-
-QT_END_NAMESPACE
diff --git a/src/corelib/tools/qelapsedtimer.h b/src/corelib/tools/qelapsedtimer.h
deleted file mode 100644
index 7954b41bf4..0000000000
--- a/src/corelib/tools/qelapsedtimer.h
+++ /dev/null
@@ -1,95 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtCore module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef QELAPSEDTIMER_H
-#define QELAPSEDTIMER_H
-
-#include <QtCore/qglobal.h>
-
-QT_BEGIN_NAMESPACE
-
-
-class Q_CORE_EXPORT QElapsedTimer
-{
-public:
- enum ClockType {
- SystemTime,
- MonotonicClock,
- TickCounter,
- MachAbsoluteTime,
- PerformanceCounter
- };
-
- Q_DECL_CONSTEXPR QElapsedTimer()
- : t1(Q_INT64_C(0x8000000000000000)),
- t2(Q_INT64_C(0x8000000000000000))
- {
- }
-
- static ClockType clockType() Q_DECL_NOTHROW;
- static bool isMonotonic() Q_DECL_NOTHROW;
-
- void start() Q_DECL_NOTHROW;
- qint64 restart() Q_DECL_NOTHROW;
- void invalidate() Q_DECL_NOTHROW;
- bool isValid() const Q_DECL_NOTHROW;
-
- qint64 nsecsElapsed() const Q_DECL_NOTHROW;
- qint64 elapsed() const Q_DECL_NOTHROW;
- bool hasExpired(qint64 timeout) const Q_DECL_NOTHROW;
-
- qint64 msecsSinceReference() const Q_DECL_NOTHROW;
- qint64 msecsTo(const QElapsedTimer &other) const Q_DECL_NOTHROW;
- qint64 secsTo(const QElapsedTimer &other) const Q_DECL_NOTHROW;
-
- bool operator==(const QElapsedTimer &other) const Q_DECL_NOTHROW
- { return t1 == other.t1 && t2 == other.t2; }
- bool operator!=(const QElapsedTimer &other) const Q_DECL_NOTHROW
- { return !(*this == other); }
-
- friend bool Q_CORE_EXPORT operator<(const QElapsedTimer &v1, const QElapsedTimer &v2) Q_DECL_NOTHROW;
-
-private:
- qint64 t1;
- qint64 t2;
-};
-
-QT_END_NAMESPACE
-
-#endif // QELAPSEDTIMER_H
diff --git a/src/corelib/tools/qelapsedtimer_generic.cpp b/src/corelib/tools/qelapsedtimer_generic.cpp
deleted file mode 100644
index 8c724247be..0000000000
--- a/src/corelib/tools/qelapsedtimer_generic.cpp
+++ /dev/null
@@ -1,204 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtCore module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include "qelapsedtimer.h"
-#include "qdatetime.h"
-
-QT_BEGIN_NAMESPACE
-
-/*!
- Returns the clock type that this QElapsedTimer implementation uses.
-
- \sa isMonotonic()
-*/
-QElapsedTimer::ClockType QElapsedTimer::clockType() Q_DECL_NOTHROW
-{
- return SystemTime;
-}
-
-/*!
- Returns \c true if this is a monotonic clock, false otherwise. See the
- information on the different clock types to understand which ones are
- monotonic.
-
- \sa clockType(), QElapsedTimer::ClockType
-*/
-bool QElapsedTimer::isMonotonic() Q_DECL_NOTHROW
-{
- return false;
-}
-
-/*!
- Starts this timer. Once started, a timer value can be checked with elapsed() or msecsSinceReference().
-
- Normally, a timer is started just before a lengthy operation, such as:
- \snippet qelapsedtimer/main.cpp 0
-
- Also, starting a timer makes it valid again.
-
- \sa restart(), invalidate(), elapsed()
-*/
-void QElapsedTimer::start() Q_DECL_NOTHROW
-{
- restart();
-}
-
-/*!
- Restarts the timer and returns the time elapsed since the previous start.
- This function is equivalent to obtaining the elapsed time with elapsed()
- and then starting the timer again with start(), but it does so in one
- single operation, avoiding the need to obtain the clock value twice.
-
- Calling this function on a QElapsedTimer that is invalid
- results in undefined behavior.
-
- The following example illustrates how to use this function to calibrate a
- parameter to a slow operation (for example, an iteration count) so that
- this operation takes at least 250 milliseconds:
-
- \snippet qelapsedtimer/main.cpp 3
-
- \sa start(), invalidate(), elapsed(), isValid()
-*/
-qint64 QElapsedTimer::restart() Q_DECL_NOTHROW
-{
- qint64 old = t1;
- t1 = QDateTime::currentMSecsSinceEpoch();
- t2 = 0;
- return t1 - old;
-}
-
-/*! \since 4.8
-
- Returns the number of nanoseconds since this QElapsedTimer was last
- started.
-
- Calling this function on a QElapsedTimer that is invalid
- results in undefined behavior.
-
- On platforms that do not provide nanosecond resolution, the value returned
- will be the best estimate available.
-
- \sa start(), restart(), hasExpired(), invalidate()
-*/
-qint64 QElapsedTimer::nsecsElapsed() const Q_DECL_NOTHROW
-{
- return elapsed() * 1000000;
-}
-
-/*!
- Returns the number of milliseconds since this QElapsedTimer was last
- started.
-
- Calling this function on a QElapsedTimer that is invalid
- results in undefined behavior.
-
- \sa start(), restart(), hasExpired(), isValid(), invalidate()
-*/
-qint64 QElapsedTimer::elapsed() const Q_DECL_NOTHROW
-{
- return QDateTime::currentMSecsSinceEpoch() - t1;
-}
-
-/*!
- Returns the number of milliseconds between last time this QElapsedTimer
- object was started and its reference clock's start.
-
- This number is usually arbitrary for all clocks except the
- QElapsedTimer::SystemTime clock. For that clock type, this number is the
- number of milliseconds since January 1st, 1970 at 0:00 UTC (that is, it
- is the Unix time expressed in milliseconds).
-
- On Linux, Windows and OS X/iOS systems, this value is usually the time
- since the system boot, though it usually does not include the time the
- system has spent in sleep states.
-
- \sa clockType(), elapsed()
-*/
-qint64 QElapsedTimer::msecsSinceReference() const Q_DECL_NOTHROW
-{
- return t1;
-}
-
-/*!
- Returns the number of milliseconds between this QElapsedTimer and \a
- other. If \a other was started before this object, the returned value
- will be negative. If it was started later, the returned value will be
- positive.
-
- The return value is undefined if this object or \a other were invalidated.
-
- \sa secsTo(), elapsed()
-*/
-qint64 QElapsedTimer::msecsTo(const QElapsedTimer &other) const Q_DECL_NOTHROW
-{
- qint64 diff = other.t1 - t1;
- return diff;
-}
-
-/*!
- Returns the number of seconds between this QElapsedTimer and \a other. If
- \a other was started before this object, the returned value will be
- negative. If it was started later, the returned value will be positive.
-
- Calling this function on or with a QElapsedTimer that is invalid
- results in undefined behavior.
-
- \sa msecsTo(), elapsed()
-*/
-qint64 QElapsedTimer::secsTo(const QElapsedTimer &other) const Q_DECL_NOTHROW
-{
- return msecsTo(other) / 1000;
-}
-
-/*!
- \relates QElapsedTimer
-
- Returns \c true if \a v1 was started before \a v2, false otherwise.
-
- The returned value is undefined if one of the two parameters is invalid
- and the other isn't. However, two invalid timers are equal and thus this
- function will return false.
-*/
-bool operator<(const QElapsedTimer &v1, const QElapsedTimer &v2) Q_DECL_NOTHROW
-{
- return v1.t1 < v2.t1;
-}
-
-QT_END_NAMESPACE
diff --git a/src/corelib/tools/qelapsedtimer_mac.cpp b/src/corelib/tools/qelapsedtimer_mac.cpp
deleted file mode 100644
index 886e0f41b2..0000000000
--- a/src/corelib/tools/qelapsedtimer_mac.cpp
+++ /dev/null
@@ -1,149 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtCore module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-// ask for the latest POSIX, just in case
-#define _POSIX_C_SOURCE 200809L
-
-#include "qelapsedtimer.h"
-#include <sys/time.h>
-#include <time.h>
-#include <unistd.h>
-
-#include <mach/mach_time.h>
-#include <private/qcore_unix_p.h>
-
-QT_BEGIN_NAMESPACE
-
-QElapsedTimer::ClockType QElapsedTimer::clockType() Q_DECL_NOTHROW
-{
- return MachAbsoluteTime;
-}
-
-bool QElapsedTimer::isMonotonic() Q_DECL_NOTHROW
-{
- return true;
-}
-
-static mach_timebase_info_data_t info = {0,0};
-static qint64 absoluteToNSecs(qint64 cpuTime)
-{
- if (info.denom == 0)
- mach_timebase_info(&info);
-#ifdef __LP64__
- __uint128_t nsecs = static_cast<__uint128_t>(cpuTime) * info.numer / info.denom;
- return static_cast<qint64>(nsecs);
-#else
- qint64 nsecs = cpuTime * info.numer / info.denom;
- return nsecs;
-#endif
-}
-
-static qint64 absoluteToMSecs(qint64 cpuTime)
-{
- return absoluteToNSecs(cpuTime) / 1000000;
-}
-
-timespec qt_gettime() Q_DECL_NOTHROW
-{
- timespec tv;
-
- uint64_t cpu_time = mach_absolute_time();
- uint64_t nsecs = absoluteToNSecs(cpu_time);
- tv.tv_sec = nsecs / 1000000000ull;
- tv.tv_nsec = nsecs - (tv.tv_sec * 1000000000ull);
- return tv;
-}
-
-void qt_nanosleep(timespec amount)
-{
- // Mac doesn't have clock_nanosleep, but it does have nanosleep.
- // nanosleep is POSIX.1-1993
-
- int r;
- EINTR_LOOP(r, nanosleep(&amount, &amount));
-}
-
-void QElapsedTimer::start() Q_DECL_NOTHROW
-{
- t1 = mach_absolute_time();
- t2 = 0;
-}
-
-qint64 QElapsedTimer::restart() Q_DECL_NOTHROW
-{
- qint64 old = t1;
- t1 = mach_absolute_time();
- t2 = 0;
-
- return absoluteToMSecs(t1 - old);
-}
-
-qint64 QElapsedTimer::nsecsElapsed() const Q_DECL_NOTHROW
-{
- uint64_t cpu_time = mach_absolute_time();
- return absoluteToNSecs(cpu_time - t1);
-}
-
-qint64 QElapsedTimer::elapsed() const Q_DECL_NOTHROW
-{
- uint64_t cpu_time = mach_absolute_time();
- return absoluteToMSecs(cpu_time - t1);
-}
-
-qint64 QElapsedTimer::msecsSinceReference() const Q_DECL_NOTHROW
-{
- return absoluteToMSecs(t1);
-}
-
-qint64 QElapsedTimer::msecsTo(const QElapsedTimer &other) const Q_DECL_NOTHROW
-{
- return absoluteToMSecs(other.t1 - t1);
-}
-
-qint64 QElapsedTimer::secsTo(const QElapsedTimer &other) const Q_DECL_NOTHROW
-{
- return msecsTo(other) / 1000;
-}
-
-bool operator<(const QElapsedTimer &v1, const QElapsedTimer &v2) Q_DECL_NOTHROW
-{
- return v1.t1 < v2.t1;
-}
-
-QT_END_NAMESPACE
diff --git a/src/corelib/tools/qelapsedtimer_unix.cpp b/src/corelib/tools/qelapsedtimer_unix.cpp
deleted file mode 100644
index e2c3ae6280..0000000000
--- a/src/corelib/tools/qelapsedtimer_unix.cpp
+++ /dev/null
@@ -1,251 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Copyright (C) 2016 Intel Corporation.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtCore module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include "qelapsedtimer.h"
-#if defined(Q_OS_VXWORKS)
-#include "qfunctions_vxworks.h"
-#else
-#include <sys/time.h>
-#include <time.h>
-#endif
-#include <unistd.h>
-
-#include <qatomic.h>
-#include "private/qcore_unix_p.h"
-
-#if defined(QT_NO_CLOCK_MONOTONIC) || defined(QT_BOOTSTRAPPED)
-// turn off the monotonic clock
-# ifdef _POSIX_MONOTONIC_CLOCK
-# undef _POSIX_MONOTONIC_CLOCK
-# endif
-# define _POSIX_MONOTONIC_CLOCK -1
-#endif
-
-QT_BEGIN_NAMESPACE
-
-/*
- * Design:
- *
- * POSIX offers a facility to select the system's monotonic clock when getting
- * the current timestamp. Whereas the functions are mandatory in POSIX.1-2008,
- * the presence of a monotonic clock is a POSIX Option (see the document
- * http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap02.html#tag_02_01_06 )
- *
- * The macro _POSIX_MONOTONIC_CLOCK can therefore assume the following values:
- * -1 monotonic clock is never supported on this system
- * 0 monotonic clock might be supported, runtime check is needed
- * >1 (such as 200809L) monotonic clock is always supported
- *
- * The unixCheckClockType() function will return the clock to use: either
- * CLOCK_MONOTONIC or CLOCK_REALTIME. In the case the POSIX option has a value
- * of zero, then this function stores a static that contains the clock to be
- * used.
- *
- * There's one extra case, which is when CLOCK_REALTIME isn't defined. When
- * that's the case, we'll emulate the clock_gettime function with gettimeofday.
- *
- * Conforming to:
- * POSIX.1b-1993 section "Clocks and Timers"
- * included in UNIX98 (Single Unix Specification v2)
- * included in POSIX.1-2001
- * see http://pubs.opengroup.org/onlinepubs/9699919799/functions/clock_getres.html
- */
-
-#if !defined(CLOCK_REALTIME)
-# define CLOCK_REALTIME 0
-static inline void qt_clock_gettime(int, struct timespec *ts)
-{
- // support clock_gettime with gettimeofday
- struct timeval tv;
- gettimeofday(&tv, 0);
- ts->tv_sec = tv.tv_sec;
- ts->tv_nsec = tv.tv_usec * 1000;
-}
-
-# ifdef _POSIX_MONOTONIC_CLOCK
-# undef _POSIX_MONOTONIC_CLOCK
-# define _POSIX_MONOTONIC_CLOCK -1
-# endif
-#else
-static inline void qt_clock_gettime(clockid_t clock, struct timespec *ts)
-{
- clock_gettime(clock, ts);
-}
-#endif
-
-static int unixCheckClockType()
-{
-#ifdef Q_OS_LINUX
- // Despite glibc claiming that we should check at runtime, the Linux kernel
- // always supports the monotonic clock
- return CLOCK_MONOTONIC;
-#elif (_POSIX_MONOTONIC_CLOCK-0 == 0) && defined(_SC_MONOTONIC_CLOCK)
- // we need a value we can store in a clockid_t that isn't a valid clock
- // check if the valid ones are both non-negative or both non-positive
-# if CLOCK_MONOTONIC >= 0 && CLOCK_REALTIME >= 0
-# define IS_VALID_CLOCK(clock) (clock >= 0)
-# define INVALID_CLOCK -1
-# elif CLOCK_MONOTONIC <= 0 && CLOCK_REALTIME <= 0
-# define IS_VALID_CLOCK(clock) (clock <= 0)
-# define INVALID_CLOCK 1
-# else
-# error "Sorry, your system has weird values for CLOCK_MONOTONIC and CLOCK_REALTIME"
-# endif
-
- static QBasicAtomicInt clockToUse = Q_BASIC_ATOMIC_INITIALIZER(INVALID_CLOCK);
- int clock = clockToUse.loadAcquire();
- if (Q_LIKELY(IS_VALID_CLOCK(clock)))
- return clock;
-
- // detect if the system supports monotonic timers
- clock = sysconf(_SC_MONOTONIC_CLOCK) > 0 ? CLOCK_MONOTONIC : CLOCK_REALTIME;
- clockToUse.storeRelease(clock);
- return clock;
-
-# undef INVALID_CLOCK
-# undef IS_VALID_CLOCK
-#elif (_POSIX_MONOTONIC_CLOCK-0) > 0
- return CLOCK_MONOTONIC;
-#else
- return CLOCK_REALTIME;
-#endif
-}
-
-bool QElapsedTimer::isMonotonic() Q_DECL_NOTHROW
-{
- return clockType() == MonotonicClock;
-}
-
-QElapsedTimer::ClockType QElapsedTimer::clockType() Q_DECL_NOTHROW
-{
- return unixCheckClockType() == CLOCK_REALTIME ? SystemTime : MonotonicClock;
-}
-
-static inline void do_gettime(qint64 *sec, qint64 *frac)
-{
- timespec ts;
- qt_clock_gettime(unixCheckClockType(), &ts);
- *sec = ts.tv_sec;
- *frac = ts.tv_nsec;
-}
-
-// used in qcore_unix.cpp and qeventdispatcher_unix.cpp
-struct timespec qt_gettime() Q_DECL_NOTHROW
-{
- qint64 sec, frac;
- do_gettime(&sec, &frac);
-
- timespec tv;
- tv.tv_sec = sec;
- tv.tv_nsec = frac;
-
- return tv;
-}
-
-void qt_nanosleep(timespec amount)
-{
- // We'd like to use clock_nanosleep.
- //
- // But clock_nanosleep is from POSIX.1-2001 and both are *not*
- // affected by clock changes when using relative sleeps, even for
- // CLOCK_REALTIME.
- //
- // nanosleep is POSIX.1-1993
-
- int r;
- EINTR_LOOP(r, nanosleep(&amount, &amount));
-}
-
-static qint64 elapsedAndRestart(qint64 sec, qint64 frac,
- qint64 *nowsec, qint64 *nowfrac)
-{
- do_gettime(nowsec, nowfrac);
- sec = *nowsec - sec;
- frac = *nowfrac - frac;
- return (sec * Q_INT64_C(1000000000) + frac) / Q_INT64_C(1000000);
-}
-
-void QElapsedTimer::start() Q_DECL_NOTHROW
-{
- do_gettime(&t1, &t2);
-}
-
-qint64 QElapsedTimer::restart() Q_DECL_NOTHROW
-{
- return elapsedAndRestart(t1, t2, &t1, &t2);
-}
-
-qint64 QElapsedTimer::nsecsElapsed() const Q_DECL_NOTHROW
-{
- qint64 sec, frac;
- do_gettime(&sec, &frac);
- sec = sec - t1;
- frac = frac - t2;
- return sec * Q_INT64_C(1000000000) + frac;
-}
-
-qint64 QElapsedTimer::elapsed() const Q_DECL_NOTHROW
-{
- return nsecsElapsed() / Q_INT64_C(1000000);
-}
-
-qint64 QElapsedTimer::msecsSinceReference() const Q_DECL_NOTHROW
-{
- return t1 * Q_INT64_C(1000) + t2 / Q_INT64_C(1000000);
-}
-
-qint64 QElapsedTimer::msecsTo(const QElapsedTimer &other) const Q_DECL_NOTHROW
-{
- qint64 secs = other.t1 - t1;
- qint64 fraction = other.t2 - t2;
- return (secs * Q_INT64_C(1000000000) + fraction) / Q_INT64_C(1000000);
-}
-
-qint64 QElapsedTimer::secsTo(const QElapsedTimer &other) const Q_DECL_NOTHROW
-{
- return other.t1 - t1;
-}
-
-bool operator<(const QElapsedTimer &v1, const QElapsedTimer &v2) Q_DECL_NOTHROW
-{
- return v1.t1 < v2.t1 || (v1.t1 == v2.t1 && v1.t2 < v2.t2);
-}
-
-QT_END_NAMESPACE
diff --git a/src/corelib/tools/qelapsedtimer_win.cpp b/src/corelib/tools/qelapsedtimer_win.cpp
deleted file mode 100644
index 734aaf80f2..0000000000
--- a/src/corelib/tools/qelapsedtimer_win.cpp
+++ /dev/null
@@ -1,193 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtCore module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include "qelapsedtimer.h"
-#include <qt_windows.h>
-
-typedef ULONGLONG (WINAPI *PtrGetTickCount64)(void);
-#if defined(Q_OS_WINRT)
- static const PtrGetTickCount64 ptrGetTickCount64 = &GetTickCount64;
-#else
- static PtrGetTickCount64 ptrGetTickCount64 = 0;
-#endif
-
-QT_BEGIN_NAMESPACE
-
-// Result of QueryPerformanceFrequency, 0 indicates that the high resolution timer is unavailable
-static quint64 counterFrequency = 0;
-
-static void resolveLibs()
-{
- static bool done = false;
- if (done)
- return;
-
-#if !defined(Q_OS_WINRT) && !defined(Q_OS_WINCE)
- // try to get GetTickCount64 from the system
- HMODULE kernel32 = GetModuleHandleW(L"kernel32");
- if (!kernel32)
- return;
- ptrGetTickCount64 = (PtrGetTickCount64)GetProcAddress(kernel32, "GetTickCount64");
-#endif // !Q_OS_WINRT && !Q_OS_WINCE
-
- // Retrieve the number of high-resolution performance counter ticks per second
- LARGE_INTEGER frequency;
- if (!QueryPerformanceFrequency(&frequency)) {
- counterFrequency = 0;
- } else {
- counterFrequency = frequency.QuadPart;
- }
-
- done = true;
-}
-
-static inline qint64 ticksToNanoseconds(qint64 ticks)
-{
- if (counterFrequency > 0) {
- // QueryPerformanceCounter uses an arbitrary frequency
- qint64 seconds = ticks / counterFrequency;
- qint64 nanoSeconds = (ticks - seconds * counterFrequency) * 1000000000 / counterFrequency;
- return seconds * 1000000000 + nanoSeconds;
- } else {
- // GetTickCount(64) return milliseconds
- return ticks * 1000000;
- }
-}
-
-static quint64 getTickCount()
-{
- resolveLibs();
-
- // This avoids a division by zero and disables the high performance counter if it's not available
- if (counterFrequency > 0) {
- LARGE_INTEGER counter;
-
- if (QueryPerformanceCounter(&counter)) {
- return counter.QuadPart;
- } else {
- qWarning("QueryPerformanceCounter failed, although QueryPerformanceFrequency succeeded.");
- return 0;
- }
- }
-
-#ifndef Q_OS_WINRT
- if (ptrGetTickCount64)
- return ptrGetTickCount64();
-
- static quint32 highdword = 0;
- static quint32 lastval = 0;
- quint32 val = GetTickCount();
- if (val < lastval)
- ++highdword;
- lastval = val;
- return val | (quint64(highdword) << 32);
-#else // !Q_OS_WINRT
- // ptrGetTickCount64 is always set on WinRT but GetTickCount is not available
- return ptrGetTickCount64();
-#endif // Q_OS_WINRT
-}
-
-quint64 qt_msectime()
-{
- return ticksToNanoseconds(getTickCount()) / 1000000;
-}
-
-QElapsedTimer::ClockType QElapsedTimer::clockType() Q_DECL_NOTHROW
-{
- resolveLibs();
-
- if (counterFrequency > 0)
- return PerformanceCounter;
- else
- return TickCounter;
-}
-
-bool QElapsedTimer::isMonotonic() Q_DECL_NOTHROW
-{
- return true;
-}
-
-void QElapsedTimer::start() Q_DECL_NOTHROW
-{
- t1 = getTickCount();
- t2 = 0;
-}
-
-qint64 QElapsedTimer::restart() Q_DECL_NOTHROW
-{
- qint64 oldt1 = t1;
- t1 = getTickCount();
- t2 = 0;
- return ticksToNanoseconds(t1 - oldt1) / 1000000;
-}
-
-qint64 QElapsedTimer::nsecsElapsed() const Q_DECL_NOTHROW
-{
- qint64 elapsed = getTickCount() - t1;
- return ticksToNanoseconds(elapsed);
-}
-
-qint64 QElapsedTimer::elapsed() const Q_DECL_NOTHROW
-{
- qint64 elapsed = getTickCount() - t1;
- return ticksToNanoseconds(elapsed) / 1000000;
-}
-
-qint64 QElapsedTimer::msecsSinceReference() const Q_DECL_NOTHROW
-{
- return ticksToNanoseconds(t1) / 1000000;
-}
-
-qint64 QElapsedTimer::msecsTo(const QElapsedTimer &other) const Q_DECL_NOTHROW
-{
- qint64 difference = other.t1 - t1;
- return ticksToNanoseconds(difference) / 1000000;
-}
-
-qint64 QElapsedTimer::secsTo(const QElapsedTimer &other) const Q_DECL_NOTHROW
-{
- return msecsTo(other) / 1000;
-}
-
-bool operator<(const QElapsedTimer &v1, const QElapsedTimer &v2) Q_DECL_NOTHROW
-{
- return (v1.t1 - v2.t1) < 0;
-}
-
-QT_END_NAMESPACE
diff --git a/src/corelib/tools/qfreelist_p.h b/src/corelib/tools/qfreelist_p.h
index ebe34bc135..c3efc41d62 100644
--- a/src/corelib/tools/qfreelist_p.h
+++ b/src/corelib/tools/qfreelist_p.h
@@ -51,6 +51,7 @@
// We mean it.
//
+#include <QtCore/private/qglobal_p.h>
#include <QtCore/qatomic.h>
QT_BEGIN_NAMESPACE
diff --git a/src/corelib/tools/qharfbuzz_p.h b/src/corelib/tools/qharfbuzz_p.h
index cc4d9bbd85..2a0307d35f 100644
--- a/src/corelib/tools/qharfbuzz_p.h
+++ b/src/corelib/tools/qharfbuzz_p.h
@@ -48,6 +48,8 @@
// We mean it.
//
+#include <QtCore/private/qglobal_p.h>
+
#ifndef QHARFBUZZ_P_H
#define QHARFBUZZ_P_H
diff --git a/src/corelib/tools/qhash.cpp b/src/corelib/tools/qhash.cpp
index 593a87e65d..abec9ebb79 100644
--- a/src/corelib/tools/qhash.cpp
+++ b/src/corelib/tools/qhash.cpp
@@ -2644,4 +2644,24 @@ uint qHash(long double key, uint seed) Q_DECL_NOTHROW
\sa QHash::constFind()
*/
+/*!
+ \fn uint qHash(const QHash<Key, T> &key, uint seed = 0)
+ \since 5.8
+ \relates QHash
+
+ Returns the hash value for the \a key, using \a seed to seed the calculation.
+
+ Type \c T must be supported by qHash().
+*/
+
+/*!
+ \fn uint qHash(const QMultiHash<Key, T> &key, uint seed = 0)
+ \since 5.8
+ \relates QMultiHash
+
+ Returns the hash value for the \a key, using \a seed to seed the calculation.
+
+ Type \c T must be supported by qHash().
+*/
+
QT_END_NAMESPACE
diff --git a/src/corelib/tools/qhash.h b/src/corelib/tools/qhash.h
index 7abbeabeae..6a2d7bdd11 100644
--- a/src/corelib/tools/qhash.h
+++ b/src/corelib/tools/qhash.h
@@ -1095,6 +1095,27 @@ Q_INLINE_TEMPLATE int QMultiHash<Key, T>::count(const Key &key, const T &value)
Q_DECLARE_ASSOCIATIVE_ITERATOR(Hash)
Q_DECLARE_MUTABLE_ASSOCIATIVE_ITERATOR(Hash)
+template <class Key, class T>
+uint qHash(const QHash<Key, T> &key, uint seed = 0)
+ Q_DECL_NOEXCEPT_EXPR(noexcept(qHash(std::declval<Key&>())) && noexcept(qHash(std::declval<T&>())))
+{
+ QtPrivate::QHashCombineCommutative hash;
+ for (auto it = key.begin(), end = key.end(); it != end; ++it) {
+ const Key &k = it.key();
+ const T &v = it.value();
+ seed = hash(seed, std::pair<const Key&, const T&>(k, v));
+ }
+ return seed;
+}
+
+template <class Key, class T>
+inline uint qHash(const QMultiHash<Key, T> &key, uint seed = 0)
+ Q_DECL_NOEXCEPT_EXPR(noexcept(qHash(std::declval<Key&>())) && noexcept(qHash(std::declval<T&>())))
+{
+ const QHash<Key, T> &key2 = key;
+ return qHash(key2, seed);
+}
+
QT_END_NAMESPACE
#if defined(Q_CC_MSVC)
diff --git a/src/corelib/tools/qline.cpp b/src/corelib/tools/qline.cpp
index b004f74be9..8942292a3d 100644
--- a/src/corelib/tools/qline.cpp
+++ b/src/corelib/tools/qline.cpp
@@ -214,6 +214,14 @@ QT_BEGIN_NAMESPACE
Returns this line translated the distance specified by \a dx and \a dy.
*/
+/*!
+ \fn QPoint QLine::center() const
+
+ \since 5.8
+
+ Returns the center point of this line. This is equivalent to
+ (p1() + p2()) / 2, except it will never overflow.
+*/
/*!
\fn void QLine::setP1(const QPoint &p1)
@@ -351,6 +359,12 @@ QDataStream &operator>>(QDataStream &stream, QLine &line)
translate() function, and can be traversed using the pointAt()
function.
+ \section1 Constraints
+
+ QLine is limited to the minimum and maximum values for the
+ \c int type. Operations on a QLine that could potentially result
+ in values outside this range will result in undefined behavior.
+
\sa QLine, QPolygonF, QRectF
*/
@@ -711,6 +725,15 @@ QLineF::IntersectType QLineF::intersect(const QLineF &l, QPointF *intersectionPo
*/
/*!
+ \fn QPointF QLineF::center() const
+
+ \since 5.8
+
+ Returns the center point of this line. This is equivalent to
+ 0.5 * p1() + 0.5 * p2().
+*/
+
+/*!
\fn void QLineF::setP1(const QPointF &p1)
\since 4.4
diff --git a/src/corelib/tools/qline.h b/src/corelib/tools/qline.h
index 819dd3fd3b..5b5ca3b4c8 100644
--- a/src/corelib/tools/qline.h
+++ b/src/corelib/tools/qline.h
@@ -76,6 +76,8 @@ public:
Q_DECL_CONSTEXPR inline QLine translated(const QPoint &p) const Q_REQUIRED_RESULT;
Q_DECL_CONSTEXPR inline QLine translated(int dx, int dy) const Q_REQUIRED_RESULT;
+ Q_DECL_CONSTEXPR inline QPoint center() const Q_REQUIRED_RESULT;
+
inline void setP1(const QPoint &p1);
inline void setP2(const QPoint &p2);
inline void setPoints(const QPoint &p1, const QPoint &p2);
@@ -165,6 +167,11 @@ Q_DECL_CONSTEXPR inline QLine QLine::translated(int adx, int ady) const
return translated(QPoint(adx, ady));
}
+Q_DECL_CONSTEXPR inline QPoint QLine::center() const
+{
+ return QPoint(int((qint64(pt1.x()) + pt2.x()) / 2), int((qint64(pt1.y()) + pt2.y()) / 2));
+}
+
inline void QLine::setP1(const QPoint &aP1)
{
pt1 = aP1;
@@ -253,6 +260,8 @@ public:
Q_DECL_CONSTEXPR inline QLineF translated(const QPointF &p) const Q_REQUIRED_RESULT;
Q_DECL_CONSTEXPR inline QLineF translated(qreal dx, qreal dy) const Q_REQUIRED_RESULT;
+ Q_DECL_CONSTEXPR inline QPointF center() const Q_REQUIRED_RESULT;
+
inline void setP1(const QPointF &p1);
inline void setP2(const QPointF &p2);
inline void setPoints(const QPointF &p1, const QPointF &p2);
@@ -357,6 +366,11 @@ Q_DECL_CONSTEXPR inline QLineF QLineF::translated(qreal adx, qreal ady) const
return translated(QPointF(adx, ady));
}
+Q_DECL_CONSTEXPR inline QPointF QLineF::center() const
+{
+ return QPointF(0.5 * pt1.x() + 0.5 * pt2.x(), 0.5 * pt1.y() + 0.5 * pt2.y());
+}
+
inline void QLineF::setLength(qreal len)
{
if (isNull())
diff --git a/src/corelib/tools/qlist.h b/src/corelib/tools/qlist.h
index 90ed5072e7..c7f27abdd6 100644
--- a/src/corelib/tools/qlist.h
+++ b/src/corelib/tools/qlist.h
@@ -118,7 +118,10 @@ struct Q_CORE_EXPORT QListData {
};
template <typename T>
-class QList : public QListSpecialMethods<T>
+class QList
+#ifndef Q_QDOC
+ : public QListSpecialMethods<T>
+#endif
{
public:
struct MemoryLayout
diff --git a/src/corelib/tools/qlocale.cpp b/src/corelib/tools/qlocale.cpp
index ea5d74d9bb..7809c513d6 100644
--- a/src/corelib/tools/qlocale.cpp
+++ b/src/corelib/tools/qlocale.cpp
@@ -61,7 +61,6 @@
#include "qvariant.h"
#include "qstringbuilder.h"
#include "private/qnumeric_p.h"
-#include "private/qsystemlibrary_p.h"
#ifdef Q_OS_WIN
# include <qt_windows.h>
# include <time.h>
diff --git a/src/corelib/tools/qlocale_data_p.h b/src/corelib/tools/qlocale_data_p.h
index 262cecb564..869153942e 100644
--- a/src/corelib/tools/qlocale_data_p.h
+++ b/src/corelib/tools/qlocale_data_p.h
@@ -51,6 +51,8 @@
// We mean it.
//
+#include <QtCore/private/qglobal_p.h>
+
QT_BEGIN_NAMESPACE
/* This part of the file isn't generated, but written by hand since
diff --git a/src/corelib/tools/qlocale_mac.mm b/src/corelib/tools/qlocale_mac.mm
index 4b1d190705..4f6efc8832 100644
--- a/src/corelib/tools/qlocale_mac.mm
+++ b/src/corelib/tools/qlocale_mac.mm
@@ -390,9 +390,6 @@ static QString macFormatCurrency(const QSystemLocale::CurrencyToStringArgument &
static QVariant macQuoteString(QSystemLocale::QueryType type, const QStringRef &str)
{
- if (QSysInfo::MacintoshVersion < QSysInfo::MV_10_6)
- return QVariant();
-
QString begin, end;
QCFType<CFLocaleRef> locale = CFLocaleCopyCurrent();
switch (type) {
diff --git a/src/corelib/tools/qlocale_p.h b/src/corelib/tools/qlocale_p.h
index f95edf4d14..c83c9d3333 100644
--- a/src/corelib/tools/qlocale_p.h
+++ b/src/corelib/tools/qlocale_p.h
@@ -52,6 +52,7 @@
// We mean it.
//
+#include <QtCore/private/qglobal_p.h>
#include "QtCore/qstring.h"
#include "QtCore/qvarlengtharray.h"
#include "QtCore/qvariant.h"
diff --git a/src/corelib/tools/qlocale_win.cpp b/src/corelib/tools/qlocale_win.cpp
index 88bfada515..f8b9f86ac6 100644
--- a/src/corelib/tools/qlocale_win.cpp
+++ b/src/corelib/tools/qlocale_win.cpp
@@ -44,9 +44,6 @@
#include "qstringlist.h"
#include "qvariant.h"
#include "qdatetime.h"
-
-#include "private/qsystemlibrary_p.h"
-
#include "qdebug.h"
#ifdef Q_OS_WIN
@@ -67,7 +64,6 @@ QT_BEGIN_NAMESPACE
#ifndef Q_OS_WINRT
static QByteArray getWinLocaleName(LCID id = LOCALE_USER_DEFAULT);
-static const char *winLangCodeToIsoName(int code);
static QString winIso639LangName(LCID id = LOCALE_USER_DEFAULT);
static QString winIso3116CtryName(LCID id = LOCALE_USER_DEFAULT);
#else // !Q_OS_WINRT
@@ -600,50 +596,32 @@ QVariant QSystemLocalePrivate::toCurrencyString(const QSystemLocale::CurrencyToS
QVariant QSystemLocalePrivate::uiLanguages()
{
- if (QSysInfo::windowsVersion() >= QSysInfo::WV_VISTA) {
- typedef BOOL (WINAPI *GetUserPreferredUILanguagesFunc) (
- DWORD dwFlags,
- PULONG pulNumLanguages,
- PWSTR pwszLanguagesBuffer,
- PULONG pcchLanguagesBuffer);
- static GetUserPreferredUILanguagesFunc GetUserPreferredUILanguages_ptr = 0;
#ifndef Q_OS_WINRT
- if (!GetUserPreferredUILanguages_ptr) {
- QSystemLibrary lib(QLatin1String("kernel32"));
- if (lib.load())
- GetUserPreferredUILanguages_ptr = (GetUserPreferredUILanguagesFunc)lib.resolve("GetUserPreferredUILanguages");
- }
-#endif // !Q_OS_WINRT
- if (GetUserPreferredUILanguages_ptr) {
- unsigned long cnt = 0;
- QVarLengthArray<wchar_t, 64> buf(64);
- unsigned long size = buf.size();
- if (!GetUserPreferredUILanguages_ptr(MUI_LANGUAGE_NAME, &cnt, buf.data(), &size)) {
- size = 0;
- if (GetLastError() == ERROR_INSUFFICIENT_BUFFER &&
- GetUserPreferredUILanguages_ptr(MUI_LANGUAGE_NAME, &cnt, NULL, &size)) {
- buf.resize(size);
- if (!GetUserPreferredUILanguages_ptr(MUI_LANGUAGE_NAME, &cnt, buf.data(), &size))
- return QStringList();
- }
- }
- QStringList result;
- result.reserve(cnt);
- const wchar_t *str = buf.constData();
- for (; cnt > 0; --cnt) {
- QString s = QString::fromWCharArray(str);
- if (s.isEmpty())
- break; // something is wrong
- result.append(s);
- str += s.size()+1;
- }
- return result;
+ unsigned long cnt = 0;
+ QVarLengthArray<wchar_t, 64> buf(64);
+# if !defined(QT_BOOTSTRAPPED) && !defined(QT_BUILD_QMAKE) // Not present in MinGW 4.9/bootstrap builds.
+ unsigned long size = buf.size();
+ if (!GetUserPreferredUILanguages(MUI_LANGUAGE_NAME, &cnt, buf.data(), &size)) {
+ size = 0;
+ if (GetLastError() == ERROR_INSUFFICIENT_BUFFER &&
+ GetUserPreferredUILanguages(MUI_LANGUAGE_NAME, &cnt, NULL, &size)) {
+ buf.resize(size);
+ if (!GetUserPreferredUILanguages(MUI_LANGUAGE_NAME, &cnt, buf.data(), &size))
+ return QStringList();
}
}
-
-#ifndef Q_OS_WINRT
- // old Windows before Vista
- return QStringList(QString::fromLatin1(winLangCodeToIsoName(GetUserDefaultUILanguage())));
+# endif // !QT_BOOTSTRAPPED && !QT_BUILD_QMAKE
+ QStringList result;
+ result.reserve(cnt);
+ const wchar_t *str = buf.constData();
+ for (; cnt > 0; --cnt) {
+ QString s = QString::fromWCharArray(str);
+ if (s.isEmpty())
+ break; // something is wrong
+ result.append(s);
+ str += s.size() + 1;
+ }
+ return result;
#else // !Q_OS_WINRT
QStringList result;
ComPtr<ABI::Windows::Globalization::IApplicationLanguagesStatics> appLanguagesStatics;
@@ -1161,19 +1139,16 @@ static QByteArray getWinLocaleName(LPWSTR id)
}
}
-#if defined(Q_OS_WINCE)
- result = winLangCodeToIsoName(id != LOCALE_USER_DEFAULT ? id : GetUserDefaultLCID());
-#else // !Q_OS_WINCE
-# ifndef Q_OS_WINRT
+#ifndef Q_OS_WINRT
if (id == LOCALE_USER_DEFAULT)
id = GetUserDefaultLCID();
-# else // !Q_OS_WINRT
+#else // !Q_OS_WINRT
WCHAR lcName[LOCALE_NAME_MAX_LENGTH];
if (QString::fromWCharArray(id) == QString::fromWCharArray(LOCALE_NAME_USER_DEFAULT)) {
GetUserDefaultLocaleName(lcName, LOCALE_NAME_MAX_LENGTH);
id = lcName;
}
-# endif // Q_OS_WINRT
+#endif // Q_OS_WINRT
QString resultuage = winIso639LangName(id);
QString country = winIso3116CtryName(id);
result = resultuage.toLatin1();
@@ -1181,7 +1156,6 @@ static QByteArray getWinLocaleName(LPWSTR id)
result += '_';
result += country.toLatin1();
}
-#endif // !Q_OS_WINCE
return result;
}
diff --git a/src/corelib/tools/qpodlist_p.h b/src/corelib/tools/qpodlist_p.h
index 810df02000..95990e0bb6 100644
--- a/src/corelib/tools/qpodlist_p.h
+++ b/src/corelib/tools/qpodlist_p.h
@@ -51,6 +51,7 @@
// We mean it.
//
+#include <QtCore/private/qglobal_p.h>
#include <QtCore/qvarlengtharray.h>
QT_BEGIN_NAMESPACE
diff --git a/src/corelib/tools/qpoint.h b/src/corelib/tools/qpoint.h
index 4e2e6b91a6..7b1004897a 100644
--- a/src/corelib/tools/qpoint.h
+++ b/src/corelib/tools/qpoint.h
@@ -42,6 +42,10 @@
#include <QtCore/qnamespace.h>
+#if defined(Q_OS_DARWIN) || defined(Q_QDOC)
+struct CGPoint;
+#endif
+
QT_BEGIN_NAMESPACE
@@ -89,6 +93,10 @@ public:
friend Q_DECL_CONSTEXPR inline const QPoint operator-(const QPoint &);
friend Q_DECL_CONSTEXPR inline const QPoint operator/(const QPoint &, qreal);
+#if defined(Q_OS_DARWIN) || defined(Q_QDOC)
+ CGPoint toCGPoint() const Q_DECL_NOTHROW Q_REQUIRED_RESULT;
+#endif
+
private:
friend class QTransform;
int xp;
@@ -247,6 +255,11 @@ public:
Q_DECL_CONSTEXPR QPoint toPoint() const;
+#if defined(Q_OS_DARWIN) || defined(Q_QDOC)
+ static QPointF fromCGPoint(CGPoint point) Q_DECL_NOTHROW Q_REQUIRED_RESULT;
+ CGPoint toCGPoint() const Q_DECL_NOTHROW Q_REQUIRED_RESULT;
+#endif
+
private:
friend class QMatrix;
friend class QTransform;
diff --git a/src/corelib/tools/qrect.h b/src/corelib/tools/qrect.h
index b376b6b999..f973cf3494 100644
--- a/src/corelib/tools/qrect.h
+++ b/src/corelib/tools/qrect.h
@@ -48,6 +48,10 @@
#error qrect.h must be included before any header file that defines topLeft
#endif
+#if defined(Q_OS_DARWIN) || defined(Q_QDOC)
+struct CGRect;
+#endif
+
QT_BEGIN_NAMESPACE
class Q_CORE_EXPORT QRect
@@ -149,6 +153,10 @@ public:
friend Q_DECL_CONSTEXPR inline bool operator==(const QRect &, const QRect &) Q_DECL_NOTHROW;
friend Q_DECL_CONSTEXPR inline bool operator!=(const QRect &, const QRect &) Q_DECL_NOTHROW;
+#if defined(Q_OS_DARWIN) || defined(Q_QDOC)
+ CGRect toCGRect() const Q_DECL_NOTHROW Q_REQUIRED_RESULT;
+#endif
+
private:
int x1;
int y1;
@@ -604,6 +612,11 @@ public:
Q_DECL_CONSTEXPR inline QRect toRect() const Q_DECL_NOTHROW Q_REQUIRED_RESULT;
QRect toAlignedRect() const Q_DECL_NOTHROW Q_REQUIRED_RESULT;
+#if defined(Q_OS_DARWIN) || defined(Q_QDOC)
+ static QRectF fromCGRect(CGRect rect) Q_DECL_NOTHROW Q_REQUIRED_RESULT;
+ CGRect toCGRect() const Q_DECL_NOTHROW Q_REQUIRED_RESULT;
+#endif
+
private:
qreal xp;
qreal yp;
diff --git a/src/corelib/tools/qringbuffer.cpp b/src/corelib/tools/qringbuffer.cpp
index 4a2dfdec2b..cb11e72435 100644
--- a/src/corelib/tools/qringbuffer.cpp
+++ b/src/corelib/tools/qringbuffer.cpp
@@ -108,24 +108,25 @@ char *QRingBuffer::reserve(qint64 bytes)
if (bytes <= 0 || bytes >= MaxByteArraySize)
return 0;
- if (buffers.isEmpty()) {
- buffers.append(QByteArray());
- buffers.first().resize(qMax(basicBlockSize, int(bytes)));
+ if (bufferSize == 0) {
+ if (buffers.isEmpty())
+ buffers.append(QByteArray(qMax(basicBlockSize, int(bytes)), Qt::Uninitialized));
+ else
+ buffers.first().resize(qMax(basicBlockSize, int(bytes)));
} else {
const qint64 newSize = bytes + tail;
- // if need buffer reallocation
- if (newSize > buffers.constLast().size()) {
- if (newSize > buffers.constLast().capacity() && (tail >= basicBlockSize
- || newSize >= MaxByteArraySize)) {
- // shrink this buffer to its current size
- buffers.last().resize(tail);
-
- // create a new QByteArray
- buffers.append(QByteArray());
- ++tailBuffer;
- tail = 0;
- }
- buffers.last().resize(qMax(basicBlockSize, tail + int(bytes)));
+ // if need a new buffer
+ if (basicBlockSize == 0 || (newSize > buffers.constLast().capacity()
+ && (tail >= basicBlockSize || newSize >= MaxByteArraySize))) {
+ // shrink this buffer to its current size
+ buffers.last().resize(tail);
+
+ // create a new QByteArray
+ buffers.append(QByteArray(qMax(basicBlockSize, int(bytes)), Qt::Uninitialized));
+ ++tailBuffer;
+ tail = 0;
+ } else if (newSize > buffers.constLast().size()) {
+ buffers.last().resize(qMax(basicBlockSize, int(newSize)));
}
}
@@ -146,10 +147,8 @@ char *QRingBuffer::reserveFront(qint64 bytes)
if (bytes <= 0 || bytes >= MaxByteArraySize)
return 0;
- if (head < bytes) {
- if (buffers.isEmpty()) {
- buffers.append(QByteArray());
- } else {
+ if (head < bytes || basicBlockSize == 0) {
+ if (head > 0) {
buffers.first().remove(0, head);
if (tailBuffer == 0)
tail -= head;
@@ -157,12 +156,15 @@ char *QRingBuffer::reserveFront(qint64 bytes)
head = qMax(basicBlockSize, int(bytes));
if (bufferSize == 0) {
+ if (buffers.isEmpty())
+ buffers.prepend(QByteArray(head, Qt::Uninitialized));
+ else
+ buffers.first().resize(head);
tail = head;
} else {
- buffers.prepend(QByteArray());
+ buffers.prepend(QByteArray(head, Qt::Uninitialized));
++tailBuffer;
}
- buffers.first().resize(head);
}
head -= int(bytes);
diff --git a/src/corelib/tools/qringbuffer_p.h b/src/corelib/tools/qringbuffer_p.h
index 9ff1ec49cf..325b71f267 100644
--- a/src/corelib/tools/qringbuffer_p.h
+++ b/src/corelib/tools/qringbuffer_p.h
@@ -51,6 +51,7 @@
// We mean it.
//
+#include <QtCore/private/qglobal_p.h>
#include <QtCore/qbytearray.h>
#include <QtCore/qlist.h>
@@ -66,6 +67,14 @@ public:
explicit inline QRingBuffer(int growth = QRINGBUFFER_CHUNKSIZE) :
head(0), tail(0), tailBuffer(0), basicBlockSize(growth), bufferSize(0) { }
+ inline void setChunkSize(int size) {
+ basicBlockSize = size;
+ }
+
+ inline int chunkSize() const {
+ return basicBlockSize;
+ }
+
inline qint64 nextDataBlockSize() const {
return (tailBuffer == 0 ? tail : buffers.first().size()) - head;
}
diff --git a/src/corelib/tools/qscopedpointer.cpp b/src/corelib/tools/qscopedpointer.cpp
index 1a37e0bc9c..67d11660e1 100644
--- a/src/corelib/tools/qscopedpointer.cpp
+++ b/src/corelib/tools/qscopedpointer.cpp
@@ -193,6 +193,48 @@ QT_BEGIN_NAMESPACE
*/
/*!
+ \fn bool operator==(const QScopedPointer<T, Cleanup> &lhs, std::nullptr_t)
+ \relates QScopedPointer
+ \since 5.8
+
+ Returns \c true if the scoped pointer \a lhs is a null pointer.
+
+ \sa QScopedPointer::isNull()
+*/
+
+/*!
+ \fn bool operator==(std::nullptr_t, const QScopedPointer<T, Cleanup> &rhs)
+ \relates QScopedPointer
+ \since 5.8
+
+ Returns \c true if the scoped pointer \a rhs is a null pointer.
+
+ \sa QScopedPointer::isNull()
+*/
+
+/*!
+ \fn bool operator!=(const QScopedPointer<T, Cleanup> &lhs, std::nullptr_t)
+ \relates QScopedPointer
+ \since 5.8
+
+ Returns \c true if the scoped pointer \a lhs is a valid (i.e. a non-null)
+ pointer.
+
+ \sa QScopedPointer::isNull()
+*/
+
+/*!
+ \fn bool operator!=(std::nullptr_t, const QScopedPointer<T, Cleanup> &rhs)
+ \relates QScopedPointer
+ \since 5.8
+
+ Returns \c true if the scoped pointer \a rhs is a valid (i.e. a non-null)
+ pointer.
+
+ \sa QScopedPointer::isNull()
+*/
+
+/*!
\fn bool QScopedPointer::isNull() const
Returns \c true if this object is holding a pointer that is \c null.
diff --git a/src/corelib/tools/qscopedpointer.h b/src/corelib/tools/qscopedpointer.h
index 3e6af97a33..92d7df6e5d 100644
--- a/src/corelib/tools/qscopedpointer.h
+++ b/src/corelib/tools/qscopedpointer.h
@@ -97,7 +97,7 @@ class QScopedPointer
{
typedef T *QScopedPointer:: *RestrictedBool;
public:
- explicit inline QScopedPointer(T *p = Q_NULLPTR) : d(p)
+ explicit QScopedPointer(T *p = Q_NULLPTR) Q_DECL_NOTHROW : d(p)
{
}
@@ -113,13 +113,12 @@ public:
return *d;
}
- inline T *operator->() const
+ T *operator->() const Q_DECL_NOTHROW
{
- Q_ASSERT(d);
return d;
}
- inline bool operator!() const
+ bool operator!() const Q_DECL_NOTHROW
{
return !d;
}
@@ -130,23 +129,23 @@ public:
return isNull() ? Q_NULLPTR : &QScopedPointer::d;
}
#else
- inline operator RestrictedBool() const
+ operator RestrictedBool() const Q_DECL_NOTHROW
{
return isNull() ? Q_NULLPTR : &QScopedPointer::d;
}
#endif
- inline T *data() const
+ T *data() const Q_DECL_NOTHROW
{
return d;
}
- inline bool isNull() const
+ bool isNull() const Q_DECL_NOTHROW
{
return !d;
}
- inline void reset(T *other = Q_NULLPTR)
+ void reset(T *other = Q_NULLPTR) Q_DECL_NOEXCEPT_EXPR(noexcept(Cleanup::cleanup(std::declval<T *>())))
{
if (d == other)
return;
@@ -155,7 +154,7 @@ public:
Cleanup::cleanup(oldD);
}
- inline T *take()
+ T *take() Q_DECL_NOTHROW
{
T *oldD = d;
d = Q_NULLPTR;
@@ -177,18 +176,42 @@ private:
};
template <class T, class Cleanup>
-inline bool operator==(const QScopedPointer<T, Cleanup> &lhs, const QScopedPointer<T, Cleanup> &rhs)
+inline bool operator==(const QScopedPointer<T, Cleanup> &lhs, const QScopedPointer<T, Cleanup> &rhs) Q_DECL_NOTHROW
{
return lhs.data() == rhs.data();
}
template <class T, class Cleanup>
-inline bool operator!=(const QScopedPointer<T, Cleanup> &lhs, const QScopedPointer<T, Cleanup> &rhs)
+inline bool operator!=(const QScopedPointer<T, Cleanup> &lhs, const QScopedPointer<T, Cleanup> &rhs) Q_DECL_NOTHROW
{
return lhs.data() != rhs.data();
}
template <class T, class Cleanup>
+inline bool operator==(const QScopedPointer<T, Cleanup> &lhs, std::nullptr_t) Q_DECL_NOTHROW
+{
+ return lhs.isNull();
+}
+
+template <class T, class Cleanup>
+inline bool operator==(std::nullptr_t, const QScopedPointer<T, Cleanup> &rhs) Q_DECL_NOTHROW
+{
+ return rhs.isNull();
+}
+
+template <class T, class Cleanup>
+inline bool operator!=(const QScopedPointer<T, Cleanup> &lhs, std::nullptr_t) Q_DECL_NOTHROW
+{
+ return !lhs.isNull();
+}
+
+template <class T, class Cleanup>
+inline bool operator!=(std::nullptr_t, const QScopedPointer<T, Cleanup> &rhs) Q_DECL_NOTHROW
+{
+ return !rhs.isNull();
+}
+
+template <class T, class Cleanup>
inline void swap(QScopedPointer<T, Cleanup> &p1, QScopedPointer<T, Cleanup> &p2) Q_DECL_NOTHROW
{ p1.swap(p2); }
diff --git a/src/corelib/tools/qscopedpointer_p.h b/src/corelib/tools/qscopedpointer_p.h
index f74a3a7945..c1c44e7695 100644
--- a/src/corelib/tools/qscopedpointer_p.h
+++ b/src/corelib/tools/qscopedpointer_p.h
@@ -48,6 +48,8 @@
// We mean it.
//
+#include <QtCore/private/qglobal_p.h>
+
#ifndef QSCOPEDPOINTER_P_H
#define QSCOPEDPOINTER_P_H
diff --git a/src/corelib/tools/qsharedpointer.cpp b/src/corelib/tools/qsharedpointer.cpp
index 84afb0c5db..af09ef6f40 100644
--- a/src/corelib/tools/qsharedpointer.cpp
+++ b/src/corelib/tools/qsharedpointer.cpp
@@ -442,15 +442,20 @@
*/
/*!
- \fn QSharedPointer::QSharedPointer(T *ptr)
+ \fn QSharedPointer::QSharedPointer(X *ptr)
Creates a QSharedPointer that points to \a ptr. The pointer \a ptr
becomes managed by this QSharedPointer and must not be passed to
another QSharedPointer object or deleted outside this object.
+
+ Since Qt 5.8, when the last reference to this QSharedPointer gets
+ destroyed, \a ptr will be deleted by calling \c X's destructor (even if \c
+ X is not the same as QSharedPointer's template parameter \c T). Previously,
+ the destructor for \c T was called.
*/
/*!
- \fn QSharedPointer::QSharedPointer(T *ptr, Deleter deleter)
+ \fn QSharedPointer::QSharedPointer(X *ptr, Deleter deleter)
Creates a QSharedPointer that points to \a ptr. The pointer \a ptr
becomes managed by this QSharedPointer and must not be passed to
@@ -477,6 +482,9 @@
}
\endcode
+ Note that the custom deleter function will be called with a pointer to type
+ \c X, even if the QSharedPointer template parameter \c T is not the same.
+
It is also possible to specify a member function directly, as in:
\code
QSharedPointer<MyObject> obj =
@@ -487,6 +495,22 @@
*/
/*!
+ \fn QSharedPointer::QSharedPointer(std::nullptr_t)
+ \since 5.8
+
+ Creates a QSharedPointer that is null. This is equivalent to the
+ QSharedPointer default constructor.
+*/
+
+/*!
+ \fn QSharedPointer::QSharedPointer(std::nullptr_t, Deleter)
+ \since 5.8
+
+ Creates a QSharedPointer that is null. This is equivalent to the
+ QSharedPointer default constructor.
+*/
+
+/*!
\fn QSharedPointer::QSharedPointer(const QSharedPointer<T> &other)
Creates a QSharedPointer object that shares \a other's pointer.
@@ -1124,6 +1148,90 @@
*/
/*!
+ \fn bool operator==(const QSharedPointer<T> &lhs, std::nullptr_t)
+ \relates QSharedPointer
+ \since 5.8
+
+ Returns \c true if the pointer referenced by \a lhs is a null pointer.
+
+ \sa QSharedPointer::isNull()
+*/
+
+/*!
+ \fn bool operator==(std::nullptr_t, const QSharedPointer<T> &rhs)
+ \relates QSharedPointer
+ \since 5.8
+
+ Returns \c true if the pointer referenced by \a rhs is a null pointer.
+
+ \sa QSharedPointer::isNull()
+*/
+
+/*!
+ \fn bool operator!=(const QSharedPointer<T> &lhs, std::nullptr_t)
+ \relates QSharedPointer
+ \since 5.8
+
+ Returns \c true if the pointer referenced by \a lhs is a valid (i.e.
+ non-null) pointer.
+
+ \sa QSharedPointer::isNull()
+*/
+
+/*!
+ \fn bool operator!=(std::nullptr_t, const QSharedPointer<T> &rhs)
+ \relates QSharedPointer
+ \since 5.8
+
+ Returns \c true if the pointer referenced by \a rhs is a valid (i.e.
+ non-null) pointer.
+
+ \sa QSharedPointer::isNull()
+*/
+
+/*!
+ \fn bool operator==(const QWeakPointer<T> &lhs, std::nullptr_t)
+ \relates QWeakPointer
+ \since 5.8
+
+ Returns \c true if the pointer referenced by \a lhs is a null pointer.
+
+ \sa QWeakPointer::isNull()
+*/
+
+/*!
+ \fn bool operator==(std::nullptr_t, const QWeakPointer<T> &rhs)
+ \relates QWeakPointer
+ \since 5.8
+
+ Returns \c true if the pointer referenced by \a rhs is a null pointer.
+
+ \sa QWeakPointer::isNull()
+*/
+
+/*!
+ \fn bool operator!=(const QWeakPointer<T> &lhs, std::nullptr_t)
+ \relates QWeakPointer
+ \since 5.8
+
+ Returns \c true if the pointer referenced by \a lhs is a valid (i.e.
+ non-null) pointer.
+
+ \sa QWeakPointer::isNull()
+*/
+
+/*!
+ \fn bool operator!=(std::nullptr_t, const QWeakPointer<T> &rhs)
+ \relates QWeakPointer
+ \since 5.8
+
+ Returns \c true if the pointer referenced by \a rhs is a valid (i.e.
+ non-null) pointer.
+
+ \sa QWeakPointer::isNull()
+*/
+
+/*!
\fn bool operator!=(const QWeakPointer<T> &ptr1, const QSharedPointer<X> &ptr2)
\relates QWeakPointer
diff --git a/src/corelib/tools/qsharedpointer.h b/src/corelib/tools/qsharedpointer.h
index 72976637d5..3b86eb238b 100644
--- a/src/corelib/tools/qsharedpointer.h
+++ b/src/corelib/tools/qsharedpointer.h
@@ -67,8 +67,10 @@ public:
// constructors
QSharedPointer();
- explicit QSharedPointer(T *ptr);
- QSharedPointer(T *ptr, Deleter d);
+ template <typename X> explicit QSharedPointer(X *ptr);
+ template <typename X, typename Deleter> QSharedPointer(X *ptr, Deleter d);
+ QSharedPointer(std::nullptr_t);
+ template <typename Deleter> QSharedPointer(std::nullptr_t, Deleter d);
QSharedPointer(const QSharedPointer<T> &other);
QSharedPointer(const QWeakPointer<T> &other);
@@ -147,6 +149,14 @@ template<class T, class X> bool operator==(const QWeakPointer<T> &ptr1, const QS
template<class T, class X> bool operator!=(const QWeakPointer<T> &ptr1, const QSharedPointer<X> &ptr2);
template<class T, class X> bool operator==(const QSharedPointer<T> &ptr1, const QWeakPointer<X> &ptr2);
template<class T, class X> bool operator!=(const QSharedPointer<T> &ptr1, const QWeakPointer<X> &ptr2);
+template<class T> bool operator==(const QSharedPointer<T> &lhs, std::nullptr_t);
+template<class T> bool operator!=(const QSharedPointer<T> &lhs, std::nullptr_t);
+template<class T> bool operator==(std::nullptr_t, const QSharedPointer<T> &rhs);
+template<class T> bool operator!=(std::nullptr_t, const QSharedPointer<T> &rhs);
+template<class T> bool operator==(const QWeakPointer<T> &lhs, std::nullptr_t);
+template<class T> bool operator!=(const QWeakPointer<T> &lhs, std::nullptr_t);
+template<class T> bool operator==(std::nullptr_t, const QWeakPointer<T> &rhs);
+template<class T> bool operator!=(std::nullptr_t, const QWeakPointer<T> &rhs);
template <class X, class T> QSharedPointer<X> qSharedPointerCast(const QSharedPointer<T> &other);
template <class X, class T> QSharedPointer<X> qSharedPointerCast(const QWeakPointer<T> &other);
diff --git a/src/corelib/tools/qsharedpointer_impl.h b/src/corelib/tools/qsharedpointer_impl.h
index fc23c29148..7ce12bc244 100644
--- a/src/corelib/tools/qsharedpointer_impl.h
+++ b/src/corelib/tools/qsharedpointer_impl.h
@@ -305,23 +305,29 @@ public:
typedef const value_type &const_reference;
typedef qptrdiff difference_type;
- inline T *data() const { return value; }
- inline bool isNull() const { return !data(); }
- inline operator RestrictedBool() const { return isNull() ? Q_NULLPTR : &QSharedPointer::value; }
- inline bool operator !() const { return isNull(); }
- inline T &operator*() const { return *data(); }
- inline T *operator->() const { return data(); }
-
- QSharedPointer() Q_DECL_NOTHROW : value(Q_NULLPTR), d(Q_NULLPTR) {}
+ T *data() const Q_DECL_NOTHROW { return value; }
+ bool isNull() const Q_DECL_NOTHROW { return !data(); }
+ operator RestrictedBool() const Q_DECL_NOTHROW { return isNull() ? Q_NULLPTR : &QSharedPointer::value; }
+ bool operator !() const Q_DECL_NOTHROW { return isNull(); }
+ T &operator*() const { return *data(); }
+ T *operator->() const Q_DECL_NOTHROW { return data(); }
+
+ Q_DECL_CONSTEXPR QSharedPointer() Q_DECL_NOTHROW : value(nullptr), d(nullptr) { }
~QSharedPointer() { deref(); }
- inline explicit QSharedPointer(T *ptr) : value(ptr) // noexcept
+ Q_DECL_CONSTEXPR QSharedPointer(std::nullptr_t) Q_DECL_NOTHROW : value(nullptr), d(nullptr) { }
+
+ template <class X>
+ inline explicit QSharedPointer(X *ptr) : value(ptr) // noexcept
{ internalConstruct(ptr, QtSharedPointer::NormalDeleter()); }
- template <typename Deleter>
- inline QSharedPointer(T *ptr, Deleter deleter) : value(ptr) // throws
+ template <class X, typename Deleter>
+ inline QSharedPointer(X *ptr, Deleter deleter) : value(ptr) // throws
{ internalConstruct(ptr, deleter); }
+ template <typename Deleter>
+ QSharedPointer(std::nullptr_t, Deleter) : value(nullptr), d(nullptr) { }
+
QSharedPointer(const QSharedPointer &other) Q_DECL_NOTHROW : value(other.value), d(other.d)
{ if (d) ref(); }
QSharedPointer &operator=(const QSharedPointer &other) Q_DECL_NOTHROW
@@ -363,7 +369,7 @@ public:
#endif
template <class X>
- inline QSharedPointer(const QSharedPointer<X> &other) : value(other.value), d(other.d)
+ QSharedPointer(const QSharedPointer<X> &other) Q_DECL_NOTHROW : value(other.value), d(other.d)
{ if (d) ref(); }
template <class X>
@@ -511,15 +517,15 @@ private:
inline void enableSharedFromThis(...) {}
- template <typename Deleter>
- inline void internalConstruct(T *ptr, Deleter deleter)
+ template <typename X, typename Deleter>
+ inline void internalConstruct(X *ptr, Deleter deleter)
{
if (!ptr) {
d = Q_NULLPTR;
return;
}
- typedef QtSharedPointer::ExternalRefCountWithCustomDeleter<T, Deleter> Private;
+ typedef QtSharedPointer::ExternalRefCountWithCustomDeleter<X, Deleter> Private;
# ifdef QT_SHAREDPOINTER_TRACK_POINTERS
typename Private::DestroyerFn actualDeleter = &Private::safetyCheckDeleter;
# else
@@ -598,10 +604,10 @@ public:
typedef const value_type &const_reference;
typedef qptrdiff difference_type;
- inline bool isNull() const { return d == Q_NULLPTR || d->strongref.load() == 0 || value == Q_NULLPTR; }
- inline operator RestrictedBool() const { return isNull() ? Q_NULLPTR : &QWeakPointer::value; }
- inline bool operator !() const { return isNull(); }
- inline T *data() const { return d == Q_NULLPTR || d->strongref.load() == 0 ? Q_NULLPTR : value; }
+ bool isNull() const Q_DECL_NOTHROW { return d == Q_NULLPTR || d->strongref.load() == 0 || value == Q_NULLPTR; }
+ operator RestrictedBool() const Q_DECL_NOTHROW { return isNull() ? Q_NULLPTR : &QWeakPointer::value; }
+ bool operator !() const Q_DECL_NOTHROW { return isNull(); }
+ T *data() const Q_DECL_NOTHROW { return d == Q_NULLPTR || d->strongref.load() == 0 ? Q_NULLPTR : value; }
inline QWeakPointer() Q_DECL_NOTHROW : d(Q_NULLPTR), value(Q_NULLPTR) { }
inline ~QWeakPointer() { if (d && !d->weakref.deref()) delete d; }
@@ -668,11 +674,11 @@ public:
}
template <class X>
- inline bool operator==(const QWeakPointer<X> &o) const
+ bool operator==(const QWeakPointer<X> &o) const Q_DECL_NOTHROW
{ return d == o.d && value == static_cast<const T *>(o.value); }
template <class X>
- inline bool operator!=(const QWeakPointer<X> &o) const
+ bool operator!=(const QWeakPointer<X> &o) const Q_DECL_NOTHROW
{ return !(*this == o); }
template <class X>
@@ -688,11 +694,11 @@ public:
}
template <class X>
- inline bool operator==(const QSharedPointer<X> &o) const
+ bool operator==(const QSharedPointer<X> &o) const Q_DECL_NOTHROW
{ return d == o.d; }
template <class X>
- inline bool operator!=(const QSharedPointer<X> &o) const
+ bool operator!=(const QSharedPointer<X> &o) const Q_DECL_NOTHROW
{ return !(*this == o); }
inline void clear() { *this = QWeakPointer(); }
@@ -774,48 +780,96 @@ public:
// operator== and operator!=
//
template <class T, class X>
-bool operator==(const QSharedPointer<T> &ptr1, const QSharedPointer<X> &ptr2)
+bool operator==(const QSharedPointer<T> &ptr1, const QSharedPointer<X> &ptr2) Q_DECL_NOTHROW
{
return ptr1.data() == ptr2.data();
}
template <class T, class X>
-bool operator!=(const QSharedPointer<T> &ptr1, const QSharedPointer<X> &ptr2)
+bool operator!=(const QSharedPointer<T> &ptr1, const QSharedPointer<X> &ptr2) Q_DECL_NOTHROW
{
return ptr1.data() != ptr2.data();
}
template <class T, class X>
-bool operator==(const QSharedPointer<T> &ptr1, const X *ptr2)
+bool operator==(const QSharedPointer<T> &ptr1, const X *ptr2) Q_DECL_NOTHROW
{
return ptr1.data() == ptr2;
}
template <class T, class X>
-bool operator==(const T *ptr1, const QSharedPointer<X> &ptr2)
+bool operator==(const T *ptr1, const QSharedPointer<X> &ptr2) Q_DECL_NOTHROW
{
return ptr1 == ptr2.data();
}
template <class T, class X>
-bool operator!=(const QSharedPointer<T> &ptr1, const X *ptr2)
+bool operator!=(const QSharedPointer<T> &ptr1, const X *ptr2) Q_DECL_NOTHROW
{
return !(ptr1 == ptr2);
}
template <class T, class X>
-bool operator!=(const T *ptr1, const QSharedPointer<X> &ptr2)
+bool operator!=(const T *ptr1, const QSharedPointer<X> &ptr2) Q_DECL_NOTHROW
{
return !(ptr2 == ptr1);
}
template <class T, class X>
-bool operator==(const QSharedPointer<T> &ptr1, const QWeakPointer<X> &ptr2)
+bool operator==(const QSharedPointer<T> &ptr1, const QWeakPointer<X> &ptr2) Q_DECL_NOTHROW
{
return ptr2 == ptr1;
}
template <class T, class X>
-bool operator!=(const QSharedPointer<T> &ptr1, const QWeakPointer<X> &ptr2)
+bool operator!=(const QSharedPointer<T> &ptr1, const QWeakPointer<X> &ptr2) Q_DECL_NOTHROW
{
return ptr2 != ptr1;
}
+template<class T>
+inline bool operator==(const QSharedPointer<T> &lhs, std::nullptr_t) Q_DECL_NOTHROW
+{
+ return lhs.isNull();
+}
+
+template<class T>
+inline bool operator!=(const QSharedPointer<T> &lhs, std::nullptr_t) Q_DECL_NOTHROW
+{
+ return !lhs.isNull();
+}
+
+template<class T>
+inline bool operator==(std::nullptr_t, const QSharedPointer<T> &rhs) Q_DECL_NOTHROW
+{
+ return rhs.isNull();
+}
+
+template<class T>
+inline bool operator!=(std::nullptr_t, const QSharedPointer<T> &rhs) Q_DECL_NOTHROW
+{
+ return !rhs.isNull();
+}
+
+template<class T>
+inline bool operator==(const QWeakPointer<T> &lhs, std::nullptr_t) Q_DECL_NOTHROW
+{
+ return lhs.isNull();
+}
+
+template<class T>
+inline bool operator!=(const QWeakPointer<T> &lhs, std::nullptr_t) Q_DECL_NOTHROW
+{
+ return !lhs.isNull();
+}
+
+template<class T>
+inline bool operator==(std::nullptr_t, const QWeakPointer<T> &rhs) Q_DECL_NOTHROW
+{
+ return rhs.isNull();
+}
+
+template<class T>
+inline bool operator!=(std::nullptr_t, const QWeakPointer<T> &rhs) Q_DECL_NOTHROW
+{
+ return !rhs.isNull();
+}
+
//
// operator-
//
diff --git a/src/corelib/tools/qsimd.cpp b/src/corelib/tools/qsimd.cpp
index c869c4e089..d4edf459de 100644
--- a/src/corelib/tools/qsimd.cpp
+++ b/src/corelib/tools/qsimd.cpp
@@ -48,16 +48,8 @@
#endif
#if defined(Q_OS_WIN)
-# if defined(Q_OS_WINCE)
-# include <qt_windows.h>
-# if _WIN32_WCE < 0x800
-# include <cmnintrin.h>
-# endif
-# endif
# if !defined(Q_CC_GNU)
-# ifndef Q_OS_WINCE
-# include <intrin.h>
-# endif
+# include <intrin.h>
# endif
#elif defined(Q_OS_LINUX) && (defined(Q_PROCESSOR_ARM) || defined(Q_PROCESSOR_MIPS_32))
#include "private/qcore_unix_p.h"
@@ -93,25 +85,6 @@ static inline uint detectProcessorFeatures()
{
return 0;
}
-#elif defined (Q_OS_WINCE)
-static inline quint64 detectProcessorFeatures()
-{
- quint64 features = 0;
-
-#if defined (ARM)
-# ifdef PF_ARM_NEON
- if (IsProcessorFeaturePresent(PF_ARM_NEON))
- features |= Q_UINT64_C(1) << CpuFeatureNEON;
-# endif
-#elif defined(_X86_)
- if (IsProcessorFeaturePresent(PF_XMMI64_INSTRUCTIONS_AVAILABLE))
- features |= Q_UINT64_C(1) << CpuFeatureSSE2;
- if (IsProcessorFeaturePresent(PF_SSE3_INSTRUCTIONS_AVAILABLE))
- features |= Q_UINT64_C(1) << CpuFeatureSSE3;
-#endif
- return features;
-}
-
#elif defined(Q_PROCESSOR_ARM)
static inline quint64 detectProcessorFeatures()
{
diff --git a/src/corelib/tools/qsimd_p.h b/src/corelib/tools/qsimd_p.h
index 7002d34654..9d8695c0f6 100644
--- a/src/corelib/tools/qsimd_p.h
+++ b/src/corelib/tools/qsimd_p.h
@@ -52,7 +52,7 @@
// We mean it.
//
-#include <qglobal.h>
+#include <QtCore/private/qglobal_p.h>
#include <qatomic.h>
/*
@@ -139,7 +139,7 @@
* }
*/
-#if defined(__MINGW64_VERSION_MAJOR) || (defined(Q_CC_MSVC) && !defined(Q_OS_WINCE))
+#if defined(__MINGW64_VERSION_MAJOR) || defined(Q_CC_MSVC)
#include <intrin.h>
#endif
@@ -465,65 +465,6 @@ static inline quint64 qCpuFeatures()
#define qCpuHasFeature(feature) ((qCompilerCpuFeatures & (Q_UINT64_C(1) << CpuFeature ## feature)) \
|| (qCpuFeatures() & (Q_UINT64_C(1) << CpuFeature ## feature)))
-#if QT_HAS_BUILTIN(__builtin_clz) && QT_HAS_BUILTIN(__builtin_ctz) && defined(Q_CC_CLANG) && !defined(Q_CC_INTEL)
-static Q_ALWAYS_INLINE unsigned _bit_scan_reverse(unsigned val)
-{
- Q_ASSERT(val != 0); // if val==0, the result is undefined.
- unsigned result = static_cast<unsigned>(__builtin_clz(val)); // Count Leading Zeros
- // Now Invert the result: clz will count *down* from the msb to the lsb, so the msb index is 31
- // and the lsb inde is 0. The result for _bit_scan_reverse is expected to be the index when
- // counting up: msb index is 0 (because it starts there), and the lsb index is 31.
- result ^= sizeof(unsigned) * 8 - 1;
- return result;
-}
-static Q_ALWAYS_INLINE unsigned _bit_scan_forward(unsigned val)
-{
- Q_ASSERT(val != 0); // if val==0, the result is undefined.
- return static_cast<unsigned>(__builtin_ctz(val)); // Count Trailing Zeros
-}
-#elif defined(Q_PROCESSOR_X86)
-// Bit scan functions for x86
-# if defined(Q_CC_MSVC)
-# if defined _WIN32_WCE && _WIN32_WCE < 0x800
-extern "C" unsigned char _BitScanForward(unsigned long* Index, unsigned long Mask);
-extern "C" unsigned char _BitScanReverse(unsigned long* Index, unsigned long Mask);
-# pragma intrinsic(_BitScanForward)
-# pragma intrinsic(_BitScanReverse)
-# endif
-// MSVC calls it _BitScanReverse and returns the carry flag, which we don't need
-static __forceinline unsigned long _bit_scan_reverse(uint val)
-{
- unsigned long result;
- _BitScanReverse(&result, val);
- return result;
-}
-static __forceinline unsigned long _bit_scan_forward(uint val)
-{
- unsigned long result;
- _BitScanForward(&result, val);
- return result;
-}
-# elif (defined(Q_CC_CLANG) || (defined(Q_CC_GNU) && Q_CC_GNU < 405)) \
- && !defined(Q_CC_INTEL)
-// Clang is missing the intrinsic for _bit_scan_reverse
-// GCC only added it in version 4.5
-static inline __attribute__((always_inline))
-unsigned _bit_scan_reverse(unsigned val)
-{
- unsigned result;
- asm("bsr %1, %0" : "=r" (result) : "r" (val));
- return result;
-}
-static inline __attribute__((always_inline))
-unsigned _bit_scan_forward(unsigned val)
-{
- unsigned result;
- asm("bsf %1, %0" : "=r" (result) : "r" (val));
- return result;
-}
-# endif
-#endif // Q_PROCESSOR_X86
-
#define ALIGNMENT_PROLOGUE_16BYTES(ptr, i, length) \
for (; i < static_cast<int>(qMin(static_cast<quintptr>(length), ((4 - ((reinterpret_cast<quintptr>(ptr) >> 2) & 0x3)) & 0x3))); ++i)
diff --git a/src/corelib/tools/qsize.h b/src/corelib/tools/qsize.h
index 5d40c4079a..cd5f8adbf5 100644
--- a/src/corelib/tools/qsize.h
+++ b/src/corelib/tools/qsize.h
@@ -42,6 +42,10 @@
#include <QtCore/qnamespace.h>
+#if defined(Q_OS_DARWIN) || defined(Q_QDOC)
+struct CGSize;
+#endif
+
QT_BEGIN_NAMESPACE
@@ -86,6 +90,10 @@ public:
friend inline Q_DECL_CONSTEXPR const QSize operator*(qreal, const QSize &) Q_DECL_NOTHROW;
friend inline const QSize operator/(const QSize &, qreal);
+#if defined(Q_OS_DARWIN) || defined(Q_QDOC)
+ CGSize toCGSize() const Q_DECL_NOTHROW Q_REQUIRED_RESULT;
+#endif
+
private:
int wd;
int ht;
@@ -248,6 +256,11 @@ public:
Q_DECL_CONSTEXPR inline QSize toSize() const Q_DECL_NOTHROW;
+#if defined(Q_OS_DARWIN) || defined(Q_QDOC)
+ static QSizeF fromCGSize(CGSize size) Q_DECL_NOTHROW Q_REQUIRED_RESULT;
+ CGSize toCGSize() const Q_DECL_NOTHROW Q_REQUIRED_RESULT;
+#endif
+
private:
qreal wd;
qreal ht;
diff --git a/src/corelib/tools/qstring.cpp b/src/corelib/tools/qstring.cpp
index dd1d296856..6b054126dd 100644
--- a/src/corelib/tools/qstring.cpp
+++ b/src/corelib/tools/qstring.cpp
@@ -81,9 +81,6 @@
#ifdef Q_OS_WIN
# include <qt_windows.h>
-# ifdef Q_OS_WINCE
-# include <winnls.h>
-# endif
#endif
#ifdef truncate
@@ -471,7 +468,7 @@ static int ucstrncmp(const QChar *a, const QChar *b, int l)
uint mask = ~_mm_movemask_epi8(result);
if (ushort(mask)) {
// found a different byte
- uint idx = uint(_bit_scan_forward(mask));
+ uint idx = qCountTrailingZeroBits(mask);
return reinterpret_cast<const QChar *>(ptr + idx)->unicode()
- reinterpret_cast<const QChar *>(ptr + distance + idx)->unicode();
}
@@ -574,7 +571,7 @@ static int ucstrncmp(const QChar *a, const uchar *c, int l)
# endif
if (mask) {
// found a different character
- uint idx = uint(_bit_scan_forward(mask));
+ uint idx = qCountTrailingZeroBits(mask);
return uc[offset + idx / 2] - c[offset + idx / 2];
}
}
@@ -592,7 +589,7 @@ static int ucstrncmp(const QChar *a, const uchar *c, int l)
uint mask = ~_mm_movemask_epi8(result);
if (ushort(mask)) {
// found a different character
- uint idx = uint(_bit_scan_forward(mask));
+ uint idx = qCountTrailingZeroBits(mask);
return uc[offset + idx / 2] - c[offset + idx / 2];
}
@@ -687,7 +684,7 @@ static int findChar(const QChar *str, int len, QChar ch, int from,
// found a match
// same as: return n - s + _bit_scan_forward(mask) / 2
return (reinterpret_cast<const char *>(n) - reinterpret_cast<const char *>(s)
- + _bit_scan_forward(mask)) >> 1;
+ + qCountTrailingZeroBits(mask)) >> 1;
}
}
@@ -1152,7 +1149,7 @@ const QString::Null QString::null = { };
has a ref count of 1, whereas QString::append() needs an extra
test).
- There are three ways you can access this improved method of string
+ There are two ways you can access this improved method of string
construction. The straightforward way is to include
\c{QStringBuilder} wherever you want to use it, and use the
\c{'%'} operator instead of \c{'+'} when concatenating strings:
@@ -3266,22 +3263,7 @@ static int lastIndexOfHelper(const ushort *haystack, int from, const ushort *nee
*/
int QString::lastIndexOf(const QString &str, int from, Qt::CaseSensitivity cs) const
{
- const int sl = str.d->size;
- if (sl == 1)
- return lastIndexOf(QChar(str.d->data()[0]), from, cs);
-
- const int l = d->size;
- if (from < 0)
- from += l;
- int delta = l-sl;
- if (from == l && sl == 0)
- return from;
- if (uint(from) >= uint(l) || delta < 0)
- return -1;
- if (from > delta)
- from = delta;
-
- return lastIndexOfHelper(d->data(), from, str.d->data(), str.d->size, cs);
+ return QStringRef(this).lastIndexOf(QStringRef(&str), from, cs);
}
/*!
@@ -3305,25 +3287,7 @@ int QString::lastIndexOf(const QString &str, int from, Qt::CaseSensitivity cs) c
*/
int QString::lastIndexOf(QLatin1String str, int from, Qt::CaseSensitivity cs) const
{
- const int sl = str.size();
- if (sl == 1)
- return lastIndexOf(QLatin1Char(str.latin1()[0]), from, cs);
-
- const int l = d->size;
- if (from < 0)
- from += l;
- int delta = l-sl;
- if (from == l && sl == 0)
- return from;
- if (uint(from) >= uint(l) || delta < 0)
- return -1;
- if (from > delta)
- from = delta;
-
- QVarLengthArray<ushort> s(sl);
- qt_from_latin1(s.data(), str.latin1(), sl);
-
- return lastIndexOfHelper(d->data(), from, s.data(), sl, cs);
+ return QStringRef(this).lastIndexOf(str, from, cs);
}
/*!
@@ -3354,23 +3318,7 @@ int QString::lastIndexOf(QChar ch, int from, Qt::CaseSensitivity cs) const
*/
int QString::lastIndexOf(const QStringRef &str, int from, Qt::CaseSensitivity cs) const
{
- const int sl = str.size();
- if (sl == 1)
- return lastIndexOf(str.at(0), from, cs);
-
- const int l = d->size;
- if (from < 0)
- from += l;
- int delta = l - sl;
- if (from == l && sl == 0)
- return from;
- if (uint(from) >= uint(l) || delta < 0)
- return -1;
- if (from > delta)
- from = delta;
-
- return lastIndexOfHelper(d->data(), from, reinterpret_cast<const ushort*>(str.unicode()),
- str.size(), cs);
+ return QStringRef(this).lastIndexOf(str, from, cs);
}
@@ -5045,7 +4993,7 @@ void QString::truncate(int pos)
If you want to remove characters from the \e beginning of the
string, use remove() instead.
- \sa truncate(), resize(), remove()
+ \sa truncate(), resize(), remove(), QStringRef::chop()
*/
void QString::chop(int n)
{
@@ -5453,9 +5401,15 @@ int QString::compare(QLatin1String other, Qt::CaseSensitivity cs) const Q_DECL_N
int QString::compare_helper(const QChar *data1, int length1, const char *data2, int length2,
Qt::CaseSensitivity cs)
{
- // ### optimize me
- const QString s2 = QString::fromUtf8(data2, length2 == -1 ? (data2 ? int(strlen(data2)) : -1) : length2);
- return compare_helper(data1, length1, s2.constData(), s2.size(), cs);
+ if (!data2)
+ return length1;
+ if (Q_UNLIKELY(length2 < 0))
+ length2 = int(strlen(data2));
+ // ### make me nothrow in all cases
+ QVarLengthArray<ushort> s2(length2);
+ const auto beg = reinterpret_cast<QChar *>(s2.data());
+ const auto end = QUtf8::convertToUnicode(beg, data2, length2);
+ return compare_helper(data1, length1, beg, end - beg, cs);
}
/*!
@@ -5556,7 +5510,7 @@ int QString::localeAwareCompare(const QString &other) const
return localeAwareCompare_helper(constData(), length(), other.constData(), other.length());
}
-#if defined(QT_USE_ICU) && !defined(Q_OS_WIN32) && !defined(Q_OS_WINCE) && !defined (Q_OS_MAC)
+#if defined(QT_USE_ICU) && !defined(Q_OS_WIN32) && !defined(Q_OS_DARWIN)
Q_GLOBAL_STATIC(QThreadStorage<QCollator>, defaultCollator)
#endif
@@ -5571,12 +5525,12 @@ int QString::localeAwareCompare_helper(const QChar *data1, int length1,
if (length1 == 0 || length2 == 0)
return ucstrcmp(data1, length1, data2, length2);
-#if defined(Q_OS_WIN32) || defined(Q_OS_WINCE)
-#ifndef Q_OS_WINRT
+#if defined(Q_OS_WIN)
+# ifndef Q_OS_WINRT
int res = CompareString(GetUserDefaultLCID(), 0, (wchar_t*)data1, length1, (wchar_t*)data2, length2);
-#else
+# else
int res = CompareStringEx(LOCALE_NAME_USER_DEFAULT, 0, (LPCWSTR)data1, length1, (LPCWSTR)data2, length2, NULL, NULL, 0);
-#endif
+# endif
switch (res) {
case CSTR_LESS_THAN:
@@ -7983,40 +7937,6 @@ QString QString::multiArg(int numArgs, const QString **args) const
return result;
}
-
-/*! \fn QString QString::fromCFString(CFStringRef string)
- \since 5.2
-
- Constructs a new QString containing a copy of the \a string CFString.
-
- \note this function is only available on OS X and iOS.
-*/
-
-/*! \fn CFStringRef QString::toCFString() const
- \since 5.2
-
- Creates a CFString from a QString. The caller owns the CFString and is
- responsible for releasing it.
-
- \note this function is only available on OS X and iOS.
-*/
-
-/*! \fn QString QString::fromNSString(const NSString *string)
- \since 5.2
-
- Constructs a new QString containing a copy of the \a string NSString.
-
- \note this function is only available on OS X and iOS.
-*/
-
-/*! \fn NSString QString::toNSString() const
- \since 5.2
-
- Creates a NSString from a QString. The NSString is autoreleased.
-
- \note this function is only available on OS X and iOS.
-*/
-
/*! \fn bool QString::isSimpleText() const
\internal
@@ -8366,6 +8286,78 @@ QString &QString::setRawData(const QChar *unicode, int size)
Returns the size of the Latin-1 string stored in this object.
*/
+/*! \fn QLatin1Char QLatin1String::at(int pos) const
+ \since 5.8
+
+ Returns the character at position \a pos in this object.
+
+ \note This function performs no error checking.
+ The behavior is undefined when \a pos < 0 or \a pos ≥ size().
+
+ \sa operator[]()
+*/
+
+/*! \fn QLatin1Char QLatin1String::operator[](int pos) const
+ \since 5.8
+
+ Returns the character at position \a pos in this object.
+
+ \note This function performs no error checking.
+ The behavior is undefined when \a pos < 0 or \a pos ≥ size().
+
+ \sa at()
+*/
+
+/*! \fn QLatin1String QLatin1String::mid(int start) const
+ \since 5.8
+
+ Returns the substring starting at position \a start in this object,
+ and extending to the end of the string.
+
+ \note This function performs no error checking.
+ The behavior is undefined when \a start < 0 or \a start > size().
+
+ \sa left(), right()
+*/
+
+/*! \fn QLatin1String QLatin1String::mid(int start, int length) const
+ \since 5.8
+ \overload
+
+ Returns the substring of length \a length starting at position
+ \a start in this object.
+
+ \note This function performs no error checking.
+ The behavior is undefined when \a start < 0, \a length < 0,
+ or \a start + \a length > size().
+
+ \sa left(), right()
+*/
+
+/*! \fn QLatin1String QLatin1String::left(int length) const
+ \since 5.8
+
+ Returns the substring of length \a length starting at position
+ 0 in this object.
+
+ \note This function performs no error checking.
+ The behavior is undefined when \a length < 0 or \a length > size().
+
+ \sa mid(), right()
+*/
+
+/*! \fn QLatin1String QLatin1String::right(int length) const
+ \since 5.8
+
+ Returns the substring of length \a length starting at position
+ size() - \a length in this object.
+
+ \note This function performs no error checking.
+ The behavior is undefined when \a length < 0 or \a length > size().
+
+ \sa mid(), left()
+*/
+
/*! \fn bool QLatin1String::operator==(const QString &other) const
Returns \c true if this string is equal to string \a other;
@@ -9398,6 +9390,24 @@ QStringRef QStringRef::appendTo(QString *string) const
*/
/*!
+ \overload
+ \fn int QStringRef::compare(const QByteArray &other, Qt::CaseSensitivity cs = Qt::CaseSensitive) const
+ \since 5.8
+
+ Compares this string with \a other and returns an
+ integer less than, equal to, or greater than zero if this string
+ is less than, equal to, or greater than the \a other byte array,
+ interpreted as a UTF-8 sequence.
+
+ If \a cs is Qt::CaseSensitive, the comparison is case sensitive;
+ otherwise the comparison is case insensitive.
+
+ Equivalent to \c {compare(*this, other, cs)}.
+
+ \sa QString::compare()
+*/
+
+/*!
\fn int QStringRef::localeAwareCompare(const QStringRef &s1, const QString & s2)
\since 4.5
@@ -9640,6 +9650,18 @@ QStringRef QString::midRef(int position, int n) const
*/
/*!
+ \fn void QStringRef::chop(int n)
+ \since 5.8
+
+ Removes \a n characters from the end of the string.
+
+ If \a n is greater than or equal to size(), the result is an
+ empty string; if \a n is negative, it is equivalent to passing zero.
+
+ \sa QString::chop(), truncate()
+*/
+
+/*!
\since 4.8
Returns the index position of the first occurrence of the string \a
@@ -9729,23 +9751,7 @@ int QStringRef::indexOf(const QStringRef &str, int from, Qt::CaseSensitivity cs)
*/
int QStringRef::lastIndexOf(const QString &str, int from, Qt::CaseSensitivity cs) const
{
- const int sl = str.size();
- if (sl == 1)
- return lastIndexOf(str.at(0), from, cs);
-
- const int l = size();;
- if (from < 0)
- from += l;
- int delta = l - sl;
- if (from == l && sl == 0)
- return from;
- if (uint(from) >= uint(l) || delta < 0)
- return -1;
- if (from > delta)
- from = delta;
-
- return lastIndexOfHelper(reinterpret_cast<const ushort*>(unicode()), from,
- reinterpret_cast<const ushort*>(str.unicode()), str.size(), cs);
+ return lastIndexOf(QStringRef(&str), from, cs);
}
/*!
@@ -9781,7 +9787,7 @@ int QStringRef::lastIndexOf(QLatin1String str, int from, Qt::CaseSensitivity cs)
{
const int sl = str.size();
if (sl == 1)
- return lastIndexOf(QLatin1Char(str.latin1()[0]), from, cs);
+ return lastIndexOf(str.at(0), from, cs);
const int l = size();
if (from < 0)
diff --git a/src/corelib/tools/qstring.h b/src/corelib/tools/qstring.h
index 3dda382dd5..a110c129de 100644
--- a/src/corelib/tools/qstring.h
+++ b/src/corelib/tools/qstring.h
@@ -68,11 +68,9 @@ namespace std
#error qstring.h must be included before any header file that defines truncate
#endif
-#ifdef Q_OS_MAC
+#if defined(Q_OS_DARWIN) || defined(Q_QDOC)
Q_FORWARD_DECLARE_CF_TYPE(CFString);
-# ifdef __OBJC__
Q_FORWARD_DECLARE_OBJC_CLASS(NSString);
-# endif
#endif
QT_BEGIN_NAMESPACE
@@ -99,6 +97,18 @@ public:
Q_DECL_CONSTEXPR int size() const Q_DECL_NOTHROW { return m_size; }
Q_DECL_CONSTEXPR const char *data() const Q_DECL_NOTHROW { return m_data; }
+ Q_DECL_CONSTEXPR QLatin1Char at(int i) const { return QLatin1Char(m_data[i]); }
+ Q_DECL_CONSTEXPR QLatin1Char operator[](int i) const { return at(i); }
+
+ Q_DECL_CONSTEXPR QLatin1String mid(int pos) const
+ { return QLatin1String(m_data + pos, m_size - pos); }
+ Q_DECL_CONSTEXPR QLatin1String mid(int pos, int n) const
+ { return QLatin1String(m_data + pos, n); }
+ Q_DECL_CONSTEXPR QLatin1String left(int n) const
+ { return QLatin1String(m_data, n); }
+ Q_DECL_CONSTEXPR QLatin1String right(int n) const
+ { return QLatin1String(m_data + m_size - n, n); }
+
inline bool operator==(const QString &s) const Q_DECL_NOTHROW;
inline bool operator!=(const QString &s) const Q_DECL_NOTHROW;
inline bool operator>(const QString &s) const Q_DECL_NOTHROW;
@@ -593,7 +603,7 @@ public:
Qt::CaseSensitivity cs = Qt::CaseSensitive) Q_DECL_NOTHROW
{ return -s2.compare(s1, cs); }
- int compare(const QStringRef &s, Qt::CaseSensitivity cs = Qt::CaseSensitive) const Q_DECL_NOTHROW;
+ inline int compare(const QStringRef &s, Qt::CaseSensitivity cs = Qt::CaseSensitive) const Q_DECL_NOTHROW;
static int compare(const QString &s1, const QStringRef &s2,
Qt::CaseSensitivity = Qt::CaseSensitive) Q_DECL_NOTHROW;
@@ -768,13 +778,11 @@ public:
inline std::u32string toStdU32String() const;
#endif
-#if defined(Q_OS_MAC) || defined(Q_QDOC)
+#if defined(Q_OS_DARWIN) || defined(Q_QDOC)
static QString fromCFString(CFStringRef string);
CFStringRef toCFString() const Q_DECL_CF_RETURNS_RETAINED;
-# if defined(__OBJC__) || defined(Q_QDOC)
static QString fromNSString(const NSString *string);
NSString *toNSString() const Q_DECL_NS_RETURNS_AUTORELEASED;
-# endif
#endif
// compatibility
struct Null { };
@@ -802,6 +810,16 @@ private:
Data *d;
+ friend inline bool operator==(QChar, const QString &) Q_DECL_NOTHROW;
+ friend inline bool operator< (QChar, const QString &) Q_DECL_NOTHROW;
+ friend inline bool operator> (QChar, const QString &) Q_DECL_NOTHROW;
+ friend inline bool operator==(QChar, const QStringRef &) Q_DECL_NOTHROW;
+ friend inline bool operator< (QChar, const QStringRef &) Q_DECL_NOTHROW;
+ friend inline bool operator> (QChar, const QStringRef &) Q_DECL_NOTHROW;
+ friend inline bool operator==(QChar, QLatin1String) Q_DECL_NOTHROW;
+ friend inline bool operator< (QChar, QLatin1String) Q_DECL_NOTHROW;
+ friend inline bool operator> (QChar, QLatin1String) Q_DECL_NOTHROW;
+
void reallocData(uint alloc, bool grow = false);
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
void expand(int i);
@@ -1422,6 +1440,12 @@ public:
QStringRef mid(int pos, int n = -1) const Q_REQUIRED_RESULT;
void truncate(int pos) Q_DECL_NOTHROW { m_size = qBound(0, pos, m_size); }
+ void chop(int n) Q_DECL_NOTHROW {
+ if (n >= m_size)
+ m_size = 0;
+ else if (n > 0)
+ m_size -= n;
+ }
bool startsWith(const QString &s, Qt::CaseSensitivity cs = Qt::CaseSensitive) const;
bool startsWith(QLatin1String s, Qt::CaseSensitivity cs = Qt::CaseSensitive) const;
@@ -1485,6 +1509,10 @@ public:
int compare(const QString &s, Qt::CaseSensitivity cs = Qt::CaseSensitive) const Q_DECL_NOTHROW;
int compare(const QStringRef &s, Qt::CaseSensitivity cs = Qt::CaseSensitive) const Q_DECL_NOTHROW;
int compare(QLatin1String s, Qt::CaseSensitivity cs = Qt::CaseSensitive) const Q_DECL_NOTHROW;
+#if !defined(QT_NO_CAST_FROM_ASCII) && !defined(QT_RESTRICTED_CAST_FROM_ASCII)
+ int compare(const QByteArray &s, Qt::CaseSensitivity cs = Qt::CaseSensitive) const
+ { return QString::compare_helper(unicode(), size(), s.data(), qstrnlen(s.data(), s.size()), cs); }
+#endif
static int compare(const QStringRef &s1, const QString &s2,
Qt::CaseSensitivity = Qt::CaseSensitive) Q_DECL_NOTHROW;
static int compare(const QStringRef &s1, const QStringRef &s2,
@@ -1520,24 +1548,10 @@ inline QStringRef::QStringRef(const QString *aString, int aPosition, int aSize)
inline QStringRef::QStringRef(const QString *aString)
:m_string(aString), m_position(0), m_size(aString?aString->size() : 0){}
+// QStringRef <> QStringRef
Q_CORE_EXPORT bool operator==(const QStringRef &s1, const QStringRef &s2) Q_DECL_NOTHROW;
inline bool operator!=(const QStringRef &s1, const QStringRef &s2) Q_DECL_NOTHROW
{ return !(s1 == s2); }
-Q_CORE_EXPORT bool operator==(const QString &s1, const QStringRef &s2) Q_DECL_NOTHROW;
-inline bool operator!=(const QString &s1, const QStringRef &s2) Q_DECL_NOTHROW
-{ return !(s1 == s2); }
-inline bool operator==(const QStringRef &s1, const QString &s2) Q_DECL_NOTHROW
-{ return s2 == s1; }
-inline bool operator!=(const QStringRef &s1, const QString &s2) Q_DECL_NOTHROW
-{ return s2 != s1; }
-Q_CORE_EXPORT bool operator==(QLatin1String s1, const QStringRef &s2) Q_DECL_NOTHROW;
-inline bool operator!=(QLatin1String s1, const QStringRef &s2) Q_DECL_NOTHROW
-{ return !(s1 == s2); }
-inline bool operator==(const QStringRef &s1, QLatin1String s2) Q_DECL_NOTHROW
-{ return s2 == s1; }
-inline bool operator!=(const QStringRef &s1, QLatin1String s2) Q_DECL_NOTHROW
-{ return s2 != s1; }
-
Q_CORE_EXPORT bool operator<(const QStringRef &s1, const QStringRef &s2) Q_DECL_NOTHROW;
inline bool operator>(const QStringRef &s1, const QStringRef &s2) Q_DECL_NOTHROW
{ return s2 < s1; }
@@ -1546,7 +1560,127 @@ inline bool operator<=(const QStringRef &s1, const QStringRef &s2) Q_DECL_NOTHRO
inline bool operator>=(const QStringRef &s1, const QStringRef &s2) Q_DECL_NOTHROW
{ return !(s1 < s2); }
+// QString <> QStringRef
+Q_CORE_EXPORT bool operator==(const QString &lhs, const QStringRef &rhs) Q_DECL_NOTHROW;
+inline bool operator!=(const QString &lhs, const QStringRef &rhs) Q_DECL_NOTHROW { return lhs.compare(rhs) != 0; }
+inline bool operator< (const QString &lhs, const QStringRef &rhs) Q_DECL_NOTHROW { return lhs.compare(rhs) < 0; }
+inline bool operator> (const QString &lhs, const QStringRef &rhs) Q_DECL_NOTHROW { return lhs.compare(rhs) > 0; }
+inline bool operator<=(const QString &lhs, const QStringRef &rhs) Q_DECL_NOTHROW { return lhs.compare(rhs) <= 0; }
+inline bool operator>=(const QString &lhs, const QStringRef &rhs) Q_DECL_NOTHROW { return lhs.compare(rhs) >= 0; }
+
+inline bool operator==(const QStringRef &lhs, const QString &rhs) Q_DECL_NOTHROW { return rhs == lhs; }
+inline bool operator!=(const QStringRef &lhs, const QString &rhs) Q_DECL_NOTHROW { return rhs != lhs; }
+inline bool operator< (const QStringRef &lhs, const QString &rhs) Q_DECL_NOTHROW { return rhs > lhs; }
+inline bool operator> (const QStringRef &lhs, const QString &rhs) Q_DECL_NOTHROW { return rhs < lhs; }
+inline bool operator<=(const QStringRef &lhs, const QString &rhs) Q_DECL_NOTHROW { return rhs >= lhs; }
+inline bool operator>=(const QStringRef &lhs, const QString &rhs) Q_DECL_NOTHROW { return rhs <= lhs; }
+
+inline int QString::compare(const QStringRef &s, Qt::CaseSensitivity cs) const Q_DECL_NOTHROW
+{ return QString::compare_helper(constData(), length(), s.constData(), s.length(), cs); }
+inline int QString::compare(const QString &s1, const QStringRef &s2, Qt::CaseSensitivity cs) Q_DECL_NOTHROW
+{ return QString::compare_helper(s1.constData(), s1.length(), s2.constData(), s2.length(), cs); }
+inline int QStringRef::compare(const QString &s, Qt::CaseSensitivity cs) const Q_DECL_NOTHROW
+{ return QString::compare_helper(constData(), length(), s.constData(), s.length(), cs); }
+inline int QStringRef::compare(const QStringRef &s, Qt::CaseSensitivity cs) const Q_DECL_NOTHROW
+{ return QString::compare_helper(constData(), length(), s.constData(), s.length(), cs); }
+inline int QStringRef::compare(QLatin1String s, Qt::CaseSensitivity cs) const Q_DECL_NOTHROW
+{ return QString::compare_helper(constData(), length(), s, cs); }
+inline int QStringRef::compare(const QStringRef &s1, const QString &s2, Qt::CaseSensitivity cs) Q_DECL_NOTHROW
+{ return QString::compare_helper(s1.constData(), s1.length(), s2.constData(), s2.length(), cs); }
+inline int QStringRef::compare(const QStringRef &s1, const QStringRef &s2, Qt::CaseSensitivity cs) Q_DECL_NOTHROW
+{ return QString::compare_helper(s1.constData(), s1.length(), s2.constData(), s2.length(), cs); }
+inline int QStringRef::compare(const QStringRef &s1, QLatin1String s2, Qt::CaseSensitivity cs) Q_DECL_NOTHROW
+{ return QString::compare_helper(s1.constData(), s1.length(), s2, cs); }
+
+// QLatin1String <> QStringRef
+Q_CORE_EXPORT bool operator==(QLatin1String lhs, const QStringRef &rhs) Q_DECL_NOTHROW;
+inline bool operator!=(QLatin1String lhs, const QStringRef &rhs) Q_DECL_NOTHROW { return rhs.compare(lhs) != 0; }
+inline bool operator< (QLatin1String lhs, const QStringRef &rhs) Q_DECL_NOTHROW { return rhs.compare(lhs) > 0; }
+inline bool operator> (QLatin1String lhs, const QStringRef &rhs) Q_DECL_NOTHROW { return rhs.compare(lhs) < 0; }
+inline bool operator<=(QLatin1String lhs, const QStringRef &rhs) Q_DECL_NOTHROW { return rhs.compare(lhs) >= 0; }
+inline bool operator>=(QLatin1String lhs, const QStringRef &rhs) Q_DECL_NOTHROW { return rhs.compare(lhs) <= 0; }
+
+inline bool operator==(const QStringRef &lhs, QLatin1String rhs) Q_DECL_NOTHROW { return rhs == lhs; }
+inline bool operator!=(const QStringRef &lhs, QLatin1String rhs) Q_DECL_NOTHROW { return rhs != lhs; }
+inline bool operator< (const QStringRef &lhs, QLatin1String rhs) Q_DECL_NOTHROW { return rhs > lhs; }
+inline bool operator> (const QStringRef &lhs, QLatin1String rhs) Q_DECL_NOTHROW { return rhs < lhs; }
+inline bool operator<=(const QStringRef &lhs, QLatin1String rhs) Q_DECL_NOTHROW { return rhs >= lhs; }
+inline bool operator>=(const QStringRef &lhs, QLatin1String rhs) Q_DECL_NOTHROW { return rhs <= lhs; }
+
+// QChar <> QString
+inline bool operator==(QChar lhs, const QString &rhs) Q_DECL_NOTHROW
+{ return QString::compare_helper(&lhs, 1, rhs.data(), rhs.size()) == 0; }
+inline bool operator< (QChar lhs, const QString &rhs) Q_DECL_NOTHROW
+{ return QString::compare_helper(&lhs, 1, rhs.data(), rhs.size()) < 0; }
+inline bool operator> (QChar lhs, const QString &rhs) Q_DECL_NOTHROW
+{ return QString::compare_helper(&lhs, 1, rhs.data(), rhs.size()) > 0; }
+
+inline bool operator!=(QChar lhs, const QString &rhs) Q_DECL_NOTHROW { return !(lhs == rhs); }
+inline bool operator<=(QChar lhs, const QString &rhs) Q_DECL_NOTHROW { return !(lhs > rhs); }
+inline bool operator>=(QChar lhs, const QString &rhs) Q_DECL_NOTHROW { return !(lhs < rhs); }
+
+inline bool operator==(const QString &lhs, QChar rhs) Q_DECL_NOTHROW { return rhs == lhs; }
+inline bool operator!=(const QString &lhs, QChar rhs) Q_DECL_NOTHROW { return !(rhs == lhs); }
+inline bool operator< (const QString &lhs, QChar rhs) Q_DECL_NOTHROW { return rhs > lhs; }
+inline bool operator> (const QString &lhs, QChar rhs) Q_DECL_NOTHROW { return rhs < lhs; }
+inline bool operator<=(const QString &lhs, QChar rhs) Q_DECL_NOTHROW { return !(rhs < lhs); }
+inline bool operator>=(const QString &lhs, QChar rhs) Q_DECL_NOTHROW { return !(rhs > lhs); }
+
+// QChar <> QStringRef
+inline bool operator==(QChar lhs, const QStringRef &rhs) Q_DECL_NOTHROW
+{ return QString::compare_helper(&lhs, 1, rhs.data(), rhs.size()) == 0; }
+inline bool operator< (QChar lhs, const QStringRef &rhs) Q_DECL_NOTHROW
+{ return QString::compare_helper(&lhs, 1, rhs.data(), rhs.size()) < 0; }
+inline bool operator> (QChar lhs, const QStringRef &rhs) Q_DECL_NOTHROW
+{ return QString::compare_helper(&lhs, 1, rhs.data(), rhs.size()) > 0; }
+
+inline bool operator!=(QChar lhs, const QStringRef &rhs) Q_DECL_NOTHROW { return !(lhs == rhs); }
+inline bool operator<=(QChar lhs, const QStringRef &rhs) Q_DECL_NOTHROW { return !(lhs > rhs); }
+inline bool operator>=(QChar lhs, const QStringRef &rhs) Q_DECL_NOTHROW { return !(lhs < rhs); }
+
+inline bool operator==(const QStringRef &lhs, QChar rhs) Q_DECL_NOTHROW { return rhs == lhs; }
+inline bool operator!=(const QStringRef &lhs, QChar rhs) Q_DECL_NOTHROW { return !(rhs == lhs); }
+inline bool operator< (const QStringRef &lhs, QChar rhs) Q_DECL_NOTHROW { return rhs > lhs; }
+inline bool operator> (const QStringRef &lhs, QChar rhs) Q_DECL_NOTHROW { return rhs < lhs; }
+inline bool operator<=(const QStringRef &lhs, QChar rhs) Q_DECL_NOTHROW { return !(rhs < lhs); }
+inline bool operator>=(const QStringRef &lhs, QChar rhs) Q_DECL_NOTHROW { return !(rhs > lhs); }
+
+// QChar <> QLatin1String
+inline bool operator==(QChar lhs, QLatin1String rhs) Q_DECL_NOTHROW
+{ return QString::compare_helper(&lhs, 1, rhs) == 0; }
+inline bool operator< (QChar lhs, QLatin1String rhs) Q_DECL_NOTHROW
+{ return QString::compare_helper(&lhs, 1, rhs) < 0; }
+inline bool operator> (QChar lhs, QLatin1String rhs) Q_DECL_NOTHROW
+{ return QString::compare_helper(&lhs, 1, rhs) > 0; }
+
+inline bool operator!=(QChar lhs, QLatin1String rhs) Q_DECL_NOTHROW { return !(lhs == rhs); }
+inline bool operator<=(QChar lhs, QLatin1String rhs) Q_DECL_NOTHROW { return !(lhs > rhs); }
+inline bool operator>=(QChar lhs, QLatin1String rhs) Q_DECL_NOTHROW { return !(lhs < rhs); }
+
+inline bool operator==(QLatin1String lhs, QChar rhs) Q_DECL_NOTHROW { return rhs == lhs; }
+inline bool operator!=(QLatin1String lhs, QChar rhs) Q_DECL_NOTHROW { return !(rhs == lhs); }
+inline bool operator< (QLatin1String lhs, QChar rhs) Q_DECL_NOTHROW { return rhs > lhs; }
+inline bool operator> (QLatin1String lhs, QChar rhs) Q_DECL_NOTHROW { return rhs < lhs; }
+inline bool operator<=(QLatin1String lhs, QChar rhs) Q_DECL_NOTHROW { return !(rhs < lhs); }
+inline bool operator>=(QLatin1String lhs, QChar rhs) Q_DECL_NOTHROW { return !(rhs > lhs); }
+
#if !defined(QT_NO_CAST_FROM_ASCII) && !defined(QT_RESTRICTED_CAST_FROM_ASCII)
+// QStringRef <> QByteArray
+inline QT_ASCII_CAST_WARN bool operator==(const QStringRef &lhs, const QByteArray &rhs) { return lhs.compare(rhs) == 0; }
+inline QT_ASCII_CAST_WARN bool operator!=(const QStringRef &lhs, const QByteArray &rhs) { return lhs.compare(rhs) != 0; }
+inline QT_ASCII_CAST_WARN bool operator< (const QStringRef &lhs, const QByteArray &rhs) { return lhs.compare(rhs) < 0; }
+inline QT_ASCII_CAST_WARN bool operator> (const QStringRef &lhs, const QByteArray &rhs) { return lhs.compare(rhs) > 0; }
+inline QT_ASCII_CAST_WARN bool operator<=(const QStringRef &lhs, const QByteArray &rhs) { return lhs.compare(rhs) <= 0; }
+inline QT_ASCII_CAST_WARN bool operator>=(const QStringRef &lhs, const QByteArray &rhs) { return lhs.compare(rhs) >= 0; }
+
+inline QT_ASCII_CAST_WARN bool operator==(const QByteArray &lhs, const QStringRef &rhs) { return rhs.compare(lhs) == 0; }
+inline QT_ASCII_CAST_WARN bool operator!=(const QByteArray &lhs, const QStringRef &rhs) { return rhs.compare(lhs) != 0; }
+inline QT_ASCII_CAST_WARN bool operator< (const QByteArray &lhs, const QStringRef &rhs) { return rhs.compare(lhs) > 0; }
+inline QT_ASCII_CAST_WARN bool operator> (const QByteArray &lhs, const QStringRef &rhs) { return rhs.compare(lhs) < 0; }
+inline QT_ASCII_CAST_WARN bool operator<=(const QByteArray &lhs, const QStringRef &rhs) { return rhs.compare(lhs) >= 0; }
+inline QT_ASCII_CAST_WARN bool operator>=(const QByteArray &lhs, const QStringRef &rhs) { return rhs.compare(lhs) <= 0; }
+
+// QStringRef <> const char *
inline QT_ASCII_CAST_WARN bool QStringRef::operator==(const char *s) const
{ return QString::compare_helper(constData(), size(), s, -1) == 0; }
inline QT_ASCII_CAST_WARN bool QStringRef::operator!=(const char *s) const
@@ -1574,23 +1708,6 @@ inline QT_ASCII_CAST_WARN bool operator>=(const char *s1, const QStringRef &s2)
{ return QString::compare_helper(s2.constData(), s2.size(), s1, -1) <= 0; }
#endif // !defined(QT_NO_CAST_FROM_ASCII) && !defined(QT_RESTRICTED_CAST_FROM_ASCII)
-inline int QString::compare(const QStringRef &s, Qt::CaseSensitivity cs) const Q_DECL_NOTHROW
-{ return QString::compare_helper(constData(), length(), s.constData(), s.length(), cs); }
-inline int QString::compare(const QString &s1, const QStringRef &s2, Qt::CaseSensitivity cs) Q_DECL_NOTHROW
-{ return QString::compare_helper(s1.constData(), s1.length(), s2.constData(), s2.length(), cs); }
-inline int QStringRef::compare(const QString &s, Qt::CaseSensitivity cs) const Q_DECL_NOTHROW
-{ return QString::compare_helper(constData(), length(), s.constData(), s.length(), cs); }
-inline int QStringRef::compare(const QStringRef &s, Qt::CaseSensitivity cs) const Q_DECL_NOTHROW
-{ return QString::compare_helper(constData(), length(), s.constData(), s.length(), cs); }
-inline int QStringRef::compare(QLatin1String s, Qt::CaseSensitivity cs) const Q_DECL_NOTHROW
-{ return QString::compare_helper(constData(), length(), s, cs); }
-inline int QStringRef::compare(const QStringRef &s1, const QString &s2, Qt::CaseSensitivity cs) Q_DECL_NOTHROW
-{ return QString::compare_helper(s1.constData(), s1.length(), s2.constData(), s2.length(), cs); }
-inline int QStringRef::compare(const QStringRef &s1, const QStringRef &s2, Qt::CaseSensitivity cs) Q_DECL_NOTHROW
-{ return QString::compare_helper(s1.constData(), s1.length(), s2.constData(), s2.length(), cs); }
-inline int QStringRef::compare(const QStringRef &s1, QLatin1String s2, Qt::CaseSensitivity cs) Q_DECL_NOTHROW
-{ return QString::compare_helper(s1.constData(), s1.length(), s2, cs); }
-
inline int QString::localeAwareCompare(const QStringRef &s) const
{ return localeAwareCompare_helper(constData(), length(), s.constData(), s.length()); }
inline int QString::localeAwareCompare(const QString& s1, const QStringRef& s2)
@@ -1616,6 +1733,23 @@ inline bool QStringRef::contains(const QStringRef &s, Qt::CaseSensitivity cs) co
inline QString &QString::insert(int i, const QStringRef &s)
{ return insert(i, s.constData(), s.length()); }
+#if !defined(QT_USE_FAST_OPERATOR_PLUS) && !defined(QT_USE_QSTRINGBUILDER)
+inline QString operator+(const QString &s1, const QStringRef &s2)
+{ QString t; t.reserve(s1.size() + s2.size()); t += s1; t += s2; return t; }
+inline QString operator+(const QStringRef &s1, const QString &s2)
+{ QString t; t.reserve(s1.size() + s2.size()); t += s1; t += s2; return t; }
+inline QString operator+(const QStringRef &s1, QLatin1String s2)
+{ QString t; t.reserve(s1.size() + s2.size()); t += s1; t += s2; return t; }
+inline QString operator+(QLatin1String s1, const QStringRef &s2)
+{ QString t; t.reserve(s1.size() + s2.size()); t += s1; t += s2; return t; }
+inline QString operator+(const QStringRef &s1, const QStringRef &s2)
+{ QString t; t.reserve(s1.size() + s2.size()); t += s1; t += s2; return t; }
+inline QString operator+(const QStringRef &s1, QChar s2)
+{ QString t; t.reserve(s1.size() + 1); t += s1; t += s2; return t; }
+inline QString operator+(QChar s1, const QStringRef &s2)
+{ QString t; t.reserve(1 + s2.size()); t += s1; t += s2; return t; }
+#endif // !(QT_USE_FAST_OPERATOR_PLUS || QT_USE_QSTRINGBUILDER)
+
namespace Qt {
#if QT_DEPRECATED_SINCE(5, 0)
QT_DEPRECATED inline QString escape(const QString &plain) {
diff --git a/src/corelib/tools/qstring_mac.mm b/src/corelib/tools/qstring_mac.mm
deleted file mode 100644
index 7b3d6b53c0..0000000000
--- a/src/corelib/tools/qstring_mac.mm
+++ /dev/null
@@ -1,83 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtCore module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include "qstring.h"
-
-#import <Foundation/Foundation.h>
-
-QT_BEGIN_NAMESPACE
-
-QString QString::fromCFString(CFStringRef string)
-{
- if (!string)
- return QString();
- CFIndex length = CFStringGetLength(string);
-
- // Fast path: CFStringGetCharactersPtr does not copy but may
- // return null for any and no reason.
- const UniChar *chars = CFStringGetCharactersPtr(string);
- if (chars)
- return QString(reinterpret_cast<const QChar *>(chars), length);
-
- QString ret(length, Qt::Uninitialized);
- CFStringGetCharacters(string, CFRangeMake(0, length), reinterpret_cast<UniChar *>(ret.data()));
- return ret;
-}
-
-CFStringRef QString::toCFString() const
-{
- return CFStringCreateWithCharacters(0, reinterpret_cast<const UniChar *>(unicode()), length());
-}
-
-QString QString::fromNSString(const NSString *string)
-{
- if (!string)
- return QString();
- QString qstring;
- qstring.resize([string length]);
- [string getCharacters: reinterpret_cast<unichar*>(qstring.data()) range: NSMakeRange(0, [string length])];
- return qstring;
-}
-
-NSString *QString::toNSString() const
-{
- return [NSString stringWithCharacters: reinterpret_cast<const UniChar*>(unicode()) length: length()];
-}
-
-QT_END_NAMESPACE
diff --git a/src/corelib/tools/qstringiterator_p.h b/src/corelib/tools/qstringiterator_p.h
index 2e24031ce4..7cf59ae42f 100644
--- a/src/corelib/tools/qstringiterator_p.h
+++ b/src/corelib/tools/qstringiterator_p.h
@@ -52,6 +52,7 @@
// We mean it.
//
+#include <QtCore/private/qglobal_p.h>
#include <QtCore/qstring.h>
QT_BEGIN_NAMESPACE
diff --git a/src/corelib/tools/qstringlist.h b/src/corelib/tools/qstringlist.h
index e01f9e16e8..87f15528bf 100644
--- a/src/corelib/tools/qstringlist.h
+++ b/src/corelib/tools/qstringlist.h
@@ -149,6 +149,7 @@ public:
Q_DECLARE_TYPEINFO(QStringList, Q_MOVABLE_TYPE);
+#ifndef Q_QDOC
inline QStringList *QListSpecialMethods<QString>::self()
{ return static_cast<QStringList *>(this); }
inline const QStringList *QListSpecialMethods<QString>::self() const
@@ -284,6 +285,7 @@ inline int QStringList::lastIndexOf(const QRegularExpression &rx, int from) cons
}
#endif // QT_NO_REGULAREXPRESSION
#endif // QT_BOOTSTRAPPED
+#endif // Q_QDOC
QT_END_NAMESPACE
diff --git a/src/corelib/tools/qtimezoneprivate_data_p.h b/src/corelib/tools/qtimezoneprivate_data_p.h
index b4e52af33a..6bbcb0e2cd 100644
--- a/src/corelib/tools/qtimezoneprivate_data_p.h
+++ b/src/corelib/tools/qtimezoneprivate_data_p.h
@@ -52,6 +52,8 @@
// We mean it.
//
+#include <QtCore/private/qglobal_p.h>
+
QT_BEGIN_NAMESPACE
/*
diff --git a/src/corelib/tools/qtimezoneprivate_win.cpp b/src/corelib/tools/qtimezoneprivate_win.cpp
index 8e32db48de..4febeda537 100644
--- a/src/corelib/tools/qtimezoneprivate_win.cpp
+++ b/src/corelib/tools/qtimezoneprivate_win.cpp
@@ -383,17 +383,11 @@ static void calculateTransitionsForYear(const QWinTimeZonePrivate::QWinTransitio
static QLocale::Country userCountry()
{
-#if defined(Q_OS_WINCE)
- // Guess that the syslem locale country is the right one to use
- // TODO Find if WinCE has equivalent api
- return QLocale::system().country();
-#else
const GEOID id = GetUserGeoID(GEOCLASS_NATION);
wchar_t code[3];
const int size = GetGeoInfo(id, GEO_ISO2, code, 3, 0);
return (size == 3) ? QLocalePrivate::codeToCountry(reinterpret_cast<const QChar*>(code), size)
: QLocale::AnyCountry;
-#endif // Q_OS_WINCE
}
// Create the system default time zone
diff --git a/src/corelib/tools/qtools_p.h b/src/corelib/tools/qtools_p.h
index 09adee5586..17d2ab852a 100644
--- a/src/corelib/tools/qtools_p.h
+++ b/src/corelib/tools/qtools_p.h
@@ -51,7 +51,7 @@
// We mean it.
//
-#include "QtCore/qglobal.h"
+#include "QtCore/private/qglobal_p.h"
#include <limits.h>
QT_BEGIN_NAMESPACE
diff --git a/src/corelib/tools/qunicodetables_p.h b/src/corelib/tools/qunicodetables_p.h
index cec84a2490..5a422ea4eb 100644
--- a/src/corelib/tools/qunicodetables_p.h
+++ b/src/corelib/tools/qunicodetables_p.h
@@ -50,6 +50,8 @@
// We mean it.
//
+#include <QtCore/private/qglobal_p.h>
+
#ifndef QUNICODETABLES_P_H
#define QUNICODETABLES_P_H
diff --git a/src/corelib/tools/qunicodetools_p.h b/src/corelib/tools/qunicodetools_p.h
index 5cde188656..5e2d56a226 100644
--- a/src/corelib/tools/qunicodetools_p.h
+++ b/src/corelib/tools/qunicodetools_p.h
@@ -51,6 +51,7 @@
// We mean it.
//
+#include <QtCore/private/qglobal_p.h>
#include <QtCore/qchar.h>
QT_BEGIN_NAMESPACE
diff --git a/src/corelib/tools/tools.pri b/src/corelib/tools/tools.pri
index b64ec756ba..853827e032 100644
--- a/src/corelib/tools/tools.pri
+++ b/src/corelib/tools/tools.pri
@@ -71,7 +71,6 @@ HEADERS += \
tools/qtimezoneprivate_p.h \
tools/qtimezoneprivate_data_p.h \
tools/qtools_p.h \
- tools/qelapsedtimer.h \
tools/qunicodetables_p.h \
tools/qunicodetools_p.h \
tools/qvarlengtharray.h \
@@ -92,7 +91,6 @@ SOURCES += \
tools/qdatetime.cpp \
tools/qdatetimeparser.cpp \
tools/qeasingcurve.cpp \
- tools/qelapsedtimer.cpp \
tools/qfreelist.cpp \
tools/qhash.cpp \
tools/qline.cpp \
@@ -130,33 +128,29 @@ msvc: NO_PCH_SOURCES += tools/qvector_msvc.cpp
false: SOURCES += $$NO_PCH_SOURCES # Hack for QtCreator
!nacl:mac: {
- SOURCES += tools/qelapsedtimer_mac.cpp
OBJECTIVE_SOURCES += tools/qlocale_mac.mm \
tools/qtimezoneprivate_mac.mm \
- tools/qstring_mac.mm \
- tools/qbytearray_mac.mm \
- tools/qdatetime_mac.mm
}
else:android {
- SOURCES += tools/qelapsedtimer_unix.cpp tools/qlocale_unix.cpp tools/qtimezoneprivate_android.cpp
+ SOURCES += tools/qlocale_unix.cpp tools/qtimezoneprivate_android.cpp
}
else:unix {
- SOURCES += tools/qelapsedtimer_unix.cpp tools/qlocale_unix.cpp tools/qtimezoneprivate_tz.cpp
+ SOURCES += tools/qlocale_unix.cpp tools/qtimezoneprivate_tz.cpp
}
else:win32 {
- SOURCES += tools/qelapsedtimer_win.cpp \
- tools/qlocale_win.cpp \
+ SOURCES += tools/qlocale_win.cpp \
tools/qtimezoneprivate_win.cpp
winphone: LIBS_PRIVATE += -lWindowsPhoneGlobalizationUtil
winrt-*-msvc2013: LIBS += advapi32.lib
-} else:integrity:SOURCES += tools/qelapsedtimer_unix.cpp tools/qlocale_unix.cpp
-else:SOURCES += tools/qelapsedtimer_generic.cpp
+} else:integrity {
+ SOURCES += tools/qlocale_unix.cpp
+}
-contains(QT_CONFIG, zlib) {
- include($$PWD/../../3rdparty/zlib.pri)
+contains(QT_CONFIG, system-zlib) {
+ include($$PWD/../../3rdparty/zlib_dependency.pri)
} else {
CONFIG += no_core_dep
- include($$PWD/../../3rdparty/zlib_dependency.pri)
+ include($$PWD/../../3rdparty/zlib.pri)
}
contains(QT_CONFIG,icu) {
@@ -198,12 +192,10 @@ INCLUDEPATH += ../3rdparty/md5 \
../3rdparty/md4 \
../3rdparty/sha3
-contains(QT_CONFIG, doubleconversion) {
- include($$PWD/../../3rdparty/double-conversion/double-conversion.pri)
-} else:contains(QT_CONFIG, system-doubleconversion) {
+contains(QT_CONFIG, system-doubleconversion) {
LIBS_PRIVATE += -ldouble-conversion
-} else {
- DEFINES += QT_NO_DOUBLECONVERSION
+} else: contains(QT_CONFIG, doubleconversion) {
+ include($$PWD/../../3rdparty/double-conversion/double-conversion.pri)
}
# Note: libm should be present by default becaue this is C++