summaryrefslogtreecommitdiffstats
path: root/src/corelib/tools
diff options
context:
space:
mode:
Diffstat (limited to 'src/corelib/tools')
-rw-r--r--src/corelib/tools/qbitarray.h4
-rw-r--r--src/corelib/tools/qbytearray.cpp42
-rw-r--r--src/corelib/tools/qbytearray.h4
-rw-r--r--src/corelib/tools/qchar.cpp17
-rw-r--r--src/corelib/tools/qcontiguouscache.h4
-rw-r--r--src/corelib/tools/qcryptographichash.cpp2
-rw-r--r--src/corelib/tools/qeasingcurve.cpp40
-rw-r--r--src/corelib/tools/qelapsedtimer_unix.cpp129
-rw-r--r--src/corelib/tools/qhash.h9
-rw-r--r--src/corelib/tools/qlinkedlist.h9
-rw-r--r--src/corelib/tools/qlist.h17
-rw-r--r--src/corelib/tools/qmap.h9
-rw-r--r--src/corelib/tools/qregexp.cpp3
-rw-r--r--src/corelib/tools/qregexp.h4
-rw-r--r--src/corelib/tools/qset.h4
-rw-r--r--src/corelib/tools/qshareddata.h28
-rw-r--r--src/corelib/tools/qsharedpointer_impl.h7
-rw-r--r--src/corelib/tools/qsimd.cpp306
-rw-r--r--src/corelib/tools/qsimd_p.h8
-rw-r--r--src/corelib/tools/qstring.cpp250
-rw-r--r--src/corelib/tools/qstring.h12
-rw-r--r--src/corelib/tools/qstringmatcher.cpp1
-rw-r--r--src/corelib/tools/qunicodetables.cpp119
-rw-r--r--src/corelib/tools/qunicodetables_p.h28
-rw-r--r--src/corelib/tools/qvector.h36
25 files changed, 736 insertions, 356 deletions
diff --git a/src/corelib/tools/qbitarray.h b/src/corelib/tools/qbitarray.h
index 60cdc9c..bd79904 100644
--- a/src/corelib/tools/qbitarray.h
+++ b/src/corelib/tools/qbitarray.h
@@ -63,6 +63,10 @@ public:
explicit QBitArray(int size, bool val = false);
QBitArray(const QBitArray &other) : d(other.d) {}
inline QBitArray &operator=(const QBitArray &other) { d = other.d; return *this; }
+#ifdef Q_COMPILER_RVALUE_REFS
+ inline QBitArray &operator=(QBitArray &&other)
+ { qSwap(d, other.d); return *this; }
+#endif
inline int size() const { return (d.size() << 3) - *d.constData(); }
inline int count() const { return (d.size() << 3) - *d.constData(); }
diff --git a/src/corelib/tools/qbytearray.cpp b/src/corelib/tools/qbytearray.cpp
index 3062c4a..6be3416 100644
--- a/src/corelib/tools/qbytearray.cpp
+++ b/src/corelib/tools/qbytearray.cpp
@@ -46,7 +46,6 @@
#include "qlist.h"
#include "qlocale.h"
#include "qlocale_p.h"
-#include "qunicodetables_p.h"
#include "qscopedpointer.h"
#include <qdatastream.h>
@@ -854,7 +853,7 @@ QByteArray::Data QByteArray::shared_empty = { Q_BASIC_ATOMIC_INITIALIZER(1),
This operation takes \l{constant time}, because QByteArray is
\l{implicitly shared}. This makes returning a QByteArray from a
function very fast. If a shared instance is modified, it will be
- copied (copy-on-write), and that takes \l{linear time}.
+ copied (copy-on-write), taking \l{linear time}.
\sa operator=()
*/
@@ -1190,10 +1189,18 @@ void QByteArray::chop(int n)
Example:
\snippet doc/src/snippets/code/src_corelib_tools_qbytearray.cpp 12
- This operation is typically very fast (\l{constant time}),
- because QByteArray preallocates extra space at the end of the
- character data so it can grow without reallocating the entire
- data each time.
+ Note: QByteArray is an \l{implicitly shared} class. Consequently,
+ if \e this is an empty QByteArray, then \e this will just share
+ the data held in \a ba. In this case, no copying of data is done,
+ taking \l{constant time}. If a shared instance is modified, it will
+ be copied (copy-on-write), taking \l{linear time}.
+
+ If \e this is not an empty QByteArray, a deep copy of the data is
+ performed, taking \l{linear time}.
+
+ This operation typically does not suffer from allocation overhead,
+ because QByteArray preallocates extra space at the end of the data
+ so that it may grow without reallocating for each append operation.
\sa append(), prepend()
*/
@@ -1478,7 +1485,12 @@ QByteArray QByteArray::nulTerminated() const
Note: QByteArray is an \l{implicitly shared} class. Consequently,
if \e this is an empty QByteArray, then \e this will just share
- the data held in \a ba. In this case, no copying of data is done.
+ the data held in \a ba. In this case, no copying of data is done,
+ taking \l{constant time}. If a shared instance is modified, it will
+ be copied (copy-on-write), taking \l{linear time}.
+
+ If \e this is not an empty QByteArray, a deep copy of the data is
+ performed, taking \l{linear time}.
\sa append(), insert()
*/
@@ -1551,14 +1563,18 @@ QByteArray &QByteArray::prepend(char ch)
This is the same as insert(size(), \a ba).
- This operation is typically very fast (\l{constant time}),
- because QByteArray preallocates extra space at the end of the
- character data so it can grow without reallocating the entire
- data each time.
-
Note: QByteArray is an \l{implicitly shared} class. Consequently,
if \e this is an empty QByteArray, then \e this will just share
- the data held in \a ba. In this case, no copying of data is done.
+ the data held in \a ba. In this case, no copying of data is done,
+ taking \l{constant time}. If a shared instance is modified, it will
+ be copied (copy-on-write), taking \l{linear time}.
+
+ If \e this is not an empty QByteArray, a deep copy of the data is
+ performed, taking \l{linear time}.
+
+ This operation typically does not suffer from allocation overhead,
+ because QByteArray preallocates extra space at the end of the data
+ so that it may grow without reallocating for each append operation.
\sa operator+=(), prepend(), insert()
*/
diff --git a/src/corelib/tools/qbytearray.h b/src/corelib/tools/qbytearray.h
index a3fe3f5..3cdcaab 100644
--- a/src/corelib/tools/qbytearray.h
+++ b/src/corelib/tools/qbytearray.h
@@ -144,6 +144,10 @@ public:
QByteArray &operator=(const QByteArray &);
QByteArray &operator=(const char *str);
+#ifdef Q_COMPILER_RVALUE_REFS
+ inline QByteArray &operator=(QByteArray &&other)
+ { qSwap(d, other.d); return *this; }
+#endif
inline int size() const;
bool isEmpty() const;
diff --git a/src/corelib/tools/qchar.cpp b/src/corelib/tools/qchar.cpp
index ed0af4e..bb777cd 100644
--- a/src/corelib/tools/qchar.cpp
+++ b/src/corelib/tools/qchar.cpp
@@ -1630,21 +1630,4 @@ static void canonicalOrderHelper(QString *str, QChar::UnicodeVersion version, in
}
}
-int QT_FASTCALL QUnicodeTables::script(unsigned int uc)
-{
- if (uc > 0xffff)
- return Common;
- int script = uc_scripts[uc >> 7];
- if (script < ScriptSentinel)
- return script;
- script = (((script - ScriptSentinel) * UnicodeBlockSize) + UnicodeBlockCount);
- script = uc_scripts[script + (uc & 0x7f)];
- return script;
-}
-
-Q_CORE_EXPORT QUnicodeTables::LineBreakClass QT_FASTCALL QUnicodeTables::lineBreakClass(uint ucs4)
-{
- return (QUnicodeTables::LineBreakClass) qGetProp(ucs4)->line_break_class;
-}
-
QT_END_NAMESPACE
diff --git a/src/corelib/tools/qcontiguouscache.h b/src/corelib/tools/qcontiguouscache.h
index f767962..4c1a846 100644
--- a/src/corelib/tools/qcontiguouscache.h
+++ b/src/corelib/tools/qcontiguouscache.h
@@ -110,6 +110,10 @@ public:
inline void setSharable(bool sharable) { if (!sharable) detach(); d->sharable = sharable; }
QContiguousCache<T> &operator=(const QContiguousCache<T> &other);
+#ifdef Q_COMPILER_RVALUE_REFS
+ inline QContiguousCache<T> &operator=(QContiguousCache<T> &&other)
+ { qSwap(d, other.d); return *this; }
+#endif
bool operator==(const QContiguousCache<T> &other) const;
inline bool operator!=(const QContiguousCache<T> &other) const { return !(*this == other); }
diff --git a/src/corelib/tools/qcryptographichash.cpp b/src/corelib/tools/qcryptographichash.cpp
index f418de9..043d6a3 100644
--- a/src/corelib/tools/qcryptographichash.cpp
+++ b/src/corelib/tools/qcryptographichash.cpp
@@ -147,7 +147,7 @@ void QCryptographicHash::addData(const char *data, int length)
}
/*!
- /overload
+ \overload addData()
*/
void QCryptographicHash::addData(const QByteArray &data)
{
diff --git a/src/corelib/tools/qeasingcurve.cpp b/src/corelib/tools/qeasingcurve.cpp
index ee791e0..7fe9170 100644
--- a/src/corelib/tools/qeasingcurve.cpp
+++ b/src/corelib/tools/qeasingcurve.cpp
@@ -332,7 +332,7 @@ public:
enum Type { In, Out, InOut, OutIn };
QEasingCurveFunction(QEasingCurveFunction::Type type = In, qreal period = 0.3, qreal amplitude = 1.0,
- qreal overshoot = 1.70158f)
+ qreal overshoot = 1.70158)
: _t(type), _p(period), _a(amplitude), _o(overshoot)
{ }
virtual ~QEasingCurveFunction() {}
@@ -359,9 +359,9 @@ QEasingCurveFunction *QEasingCurveFunction::copy() const
bool QEasingCurveFunction::operator==(const QEasingCurveFunction& other)
{
return _t == other._t &&
- _p == other._p &&
- _a == other._a &&
- _o == other._o;
+ qFuzzyCompare(_p, other._p) &&
+ qFuzzyCompare(_a, other._a) &&
+ qFuzzyCompare(_o, other._o);
}
QT_BEGIN_INCLUDE_NAMESPACE
@@ -400,8 +400,8 @@ struct ElasticEase : public QEasingCurveFunction
qreal value(qreal t)
{
- qreal p = (_p < 0) ? 0.3f : _p;
- qreal a = (_a < 0) ? 1.0f : _a;
+ qreal p = (_p < 0) ? qreal(0.3) : _p;
+ qreal a = (_a < 0) ? qreal(1.0) : _a;
switch(_t) {
case In:
return easeInElastic(t, a, p);
@@ -420,7 +420,7 @@ struct ElasticEase : public QEasingCurveFunction
struct BounceEase : public QEasingCurveFunction
{
BounceEase(Type type)
- : QEasingCurveFunction(type, 0.3f, 1.0f)
+ : QEasingCurveFunction(type, qreal(0.3), qreal(1.0))
{ }
QEasingCurveFunction *copy() const
@@ -432,7 +432,7 @@ struct BounceEase : public QEasingCurveFunction
qreal value(qreal t)
{
- qreal a = (_a < 0) ? 1.0f : _a;
+ qreal a = (_a < 0) ? qreal(1.0) : _a;
switch(_t) {
case In:
return easeInBounce(t, a);
@@ -451,7 +451,7 @@ struct BounceEase : public QEasingCurveFunction
struct BackEase : public QEasingCurveFunction
{
BackEase(Type type)
- : QEasingCurveFunction(type, 0.3f, 1.0f, 1.70158f)
+ : QEasingCurveFunction(type, qreal(0.3), qreal(1.0), qreal(1.70158))
{ }
QEasingCurveFunction *copy() const
@@ -463,7 +463,7 @@ struct BackEase : public QEasingCurveFunction
qreal value(qreal t)
{
- qreal o = (_o < 0) ? 1.70158f : _o;
+ qreal o = (_o < 0) ? qreal(1.70158) : _o;
switch(_t) {
case In:
return easeInBack(t, o);
@@ -595,7 +595,7 @@ static QEasingCurveFunction *curveToFunctionObject(QEasingCurve::Type type)
curveFunc = new BackEase(BackEase::OutIn);
break;
default:
- curveFunc = new QEasingCurveFunction(QEasingCurveFunction::In, 0.3f, 1.0f, 1.70158f); // ###
+ curveFunc = new QEasingCurveFunction(QEasingCurveFunction::In, qreal(0.3), qreal(1.0), qreal(1.70158));
}
return curveFunc;
@@ -657,9 +657,17 @@ bool QEasingCurve::operator==(const QEasingCurve &other) const
{
bool res = d_ptr->func == other.d_ptr->func
&& d_ptr->type == other.d_ptr->type;
- if (res && d_ptr->config && other.d_ptr->config) {
+ if (res) {
+ if (d_ptr->config && other.d_ptr->config) {
// catch the config content
- res = d_ptr->config->operator==(*(other.d_ptr->config));
+ res = d_ptr->config->operator==(*(other.d_ptr->config));
+
+ } else if (d_ptr->config || other.d_ptr->config) {
+ // one one has a config object, which could contain default values
+ res = qFuzzyCompare(amplitude(), other.amplitude()) &&
+ qFuzzyCompare(period(), other.period()) &&
+ qFuzzyCompare(overshoot(), other.overshoot());
+ }
}
return res;
}
@@ -681,7 +689,7 @@ bool QEasingCurve::operator==(const QEasingCurve &other) const
*/
qreal QEasingCurve::amplitude() const
{
- return d_ptr->config ? d_ptr->config->_a : 1.0;
+ return d_ptr->config ? d_ptr->config->_a : qreal(1.0);
}
/*!
@@ -705,7 +713,7 @@ void QEasingCurve::setAmplitude(qreal amplitude)
*/
qreal QEasingCurve::period() const
{
- return d_ptr->config ? d_ptr->config->_p : 0.3;
+ return d_ptr->config ? d_ptr->config->_p : qreal(0.3);
}
/*!
@@ -729,7 +737,7 @@ void QEasingCurve::setPeriod(qreal period)
*/
qreal QEasingCurve::overshoot() const
{
- return d_ptr->config ? d_ptr->config->_o : 1.70158f;
+ return d_ptr->config ? d_ptr->config->_o : qreal(1.70158) ;
}
/*!
diff --git a/src/corelib/tools/qelapsedtimer_unix.cpp b/src/corelib/tools/qelapsedtimer_unix.cpp
index 2c4ea58..633fa00 100644
--- a/src/corelib/tools/qelapsedtimer_unix.cpp
+++ b/src/corelib/tools/qelapsedtimer_unix.cpp
@@ -40,22 +40,58 @@
****************************************************************************/
#include "qelapsedtimer.h"
-#include "qpair.h"
#include <sys/time.h>
#include <time.h>
#include <unistd.h>
-#if !defined(QT_NO_CLOCK_MONOTONIC)
-# if defined(QT_BOOTSTRAPPED)
-# define QT_NO_CLOCK_MONOTONIC
+#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
-static qint64 fractionAdjustment()
+#if (_POSIX_MONOTONIC_CLOCK-0 != 0)
+static const bool monotonicClockChecked = true;
+static const bool monotonicClockAvailable = _POSIX_MONOTONIC_CLOCK > 0;
+#else
+static int monotonicClockChecked = false;
+static int monotonicClockAvailable = false;
+#endif
+
+#ifdef Q_CC_GNU
+# define is_likely(x) __builtin_expect((x), 1)
+#else
+# define is_likely(x) (x)
+#endif
+#define load_acquire(x) ((volatile const int&)(x))
+#define store_release(x,v) ((volatile int&)(x) = (v))
+
+static void unixCheckClockType()
+{
+#if (_POSIX_MONOTONIC_CLOCK-0 == 0)
+ if (is_likely(load_acquire(monotonicClockChecked)))
+ return;
+
+# if defined(_SC_MONOTONIC_CLOCK)
+ // detect if the system support monotonic timers
+ long x = sysconf(_SC_MONOTONIC_CLOCK);
+ store_release(monotonicClockAvailable, x >= 200112L);
+# endif
+
+ store_release(monotonicClockChecked, true);
+#endif
+}
+
+static inline qint64 fractionAdjustment()
{
- if (QElapsedTimer::isMonotonic()) {
+ // disabled, but otherwise indicates bad usage of QElapsedTimer
+ //Q_ASSERT(monotonicClockChecked);
+
+ if (monotonicClockAvailable) {
// the monotonic timer is measured in nanoseconds
// 1 ms = 1000000 ns
return 1000*1000ull;
@@ -68,90 +104,73 @@ static qint64 fractionAdjustment()
bool QElapsedTimer::isMonotonic()
{
-#if (_POSIX_MONOTONIC_CLOCK-0 > 0)
- return true;
-#else
- static int returnValue = 0;
-
- if (returnValue == 0) {
-# if (_POSIX_MONOTONIC_CLOCK-0 < 0) || !defined(_SC_MONOTONIC_CLOCK)
- returnValue = -1;
-# elif (_POSIX_MONOTONIC_CLOCK == 0)
- // detect if the system support monotonic timers
- long x = sysconf(_SC_MONOTONIC_CLOCK);
- returnValue = (x >= 200112L) ? 1 : -1;
-# endif
- }
-
- return returnValue != -1;
-#endif
+ unixCheckClockType();
+ return monotonicClockAvailable;
}
QElapsedTimer::ClockType QElapsedTimer::clockType()
{
- return isMonotonic() ? MonotonicClock : SystemTime;
+ unixCheckClockType();
+ return monotonicClockAvailable ? MonotonicClock : SystemTime;
}
-static inline QPair<long, long> do_gettime()
+static inline void do_gettime(qint64 *sec, qint64 *frac)
{
-#if (_POSIX_MONOTONIC_CLOCK-0 > 0)
- timespec ts;
- clock_gettime(CLOCK_MONOTONIC, &ts);
- return qMakePair<long,long>(ts.tv_sec, ts.tv_nsec);
-#else
-# if !defined(QT_NO_CLOCK_MONOTONIC) && !defined(QT_BOOTSTRAPPED)
- if (QElapsedTimer::isMonotonic()) {
+#if (_POSIX_MONOTONIC_CLOCK-0 >= 0)
+ unixCheckClockType();
+ if (is_likely(monotonicClockAvailable)) {
timespec ts;
clock_gettime(CLOCK_MONOTONIC, &ts);
- return qMakePair<long,long>(ts.tv_sec, ts.tv_nsec);
+ *sec = ts.tv_sec;
+ *frac = ts.tv_nsec;
+ return;
}
-# endif
+#endif
// use gettimeofday
timeval tv;
::gettimeofday(&tv, 0);
- return qMakePair<long,long>(tv.tv_sec, tv.tv_usec);
-#endif
+ *sec = tv.tv_sec;
+ *frac = tv.tv_usec;
}
// used in qcore_unix.cpp and qeventdispatcher_unix.cpp
timeval qt_gettime()
{
- QPair<long, long> r = do_gettime();
+ qint64 sec, frac;
+ do_gettime(&sec, &frac);
timeval tv;
- tv.tv_sec = r.first;
- tv.tv_usec = r.second;
- if (QElapsedTimer::isMonotonic())
+ tv.tv_sec = sec;
+ tv.tv_usec = frac;
+ if (monotonicClockAvailable)
tv.tv_usec /= 1000;
return tv;
}
+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(1000) + frac / fractionAdjustment();
+}
+
void QElapsedTimer::start()
{
- QPair<long, long> r = do_gettime();
- t1 = r.first;
- t2 = r.second;
+ do_gettime(&t1, &t2);
}
qint64 QElapsedTimer::restart()
{
- QPair<long, long> r = do_gettime();
- qint64 oldt1 = t1;
- qint64 oldt2 = t2;
- t1 = r.first;
- t2 = r.second;
-
- r.first -= oldt1;
- r.second -= oldt2;
- return r.first * Q_INT64_C(1000) + r.second / fractionAdjustment();
+ return elapsedAndRestart(t1, t2, &t1, &t2);
}
qint64 QElapsedTimer::elapsed() const
{
- QElapsedTimer now;
- now.start();
- return msecsTo(now);
+ qint64 sec, frac;
+ return elapsedAndRestart(t1, t2, &sec, &frac);
}
qint64 QElapsedTimer::msecsSinceReference() const
diff --git a/src/corelib/tools/qhash.h b/src/corelib/tools/qhash.h
index 360f99d..992ff33 100644
--- a/src/corelib/tools/qhash.h
+++ b/src/corelib/tools/qhash.h
@@ -283,6 +283,10 @@ public:
inline ~QHash() { if (!d->ref.deref()) freeData(d); }
QHash<Key, T> &operator=(const QHash<Key, T> &other);
+#ifdef Q_COMPILER_RVALUE_REFS
+ inline QHash<Key, T> &operator=(QHash<Key, T> &&other)
+ { qSwap(d, other.d); return *this; }
+#endif
bool operator==(const QHash<Key, T> &other) const;
inline bool operator!=(const QHash<Key, T> &other) const { return !(*this == other); }
@@ -586,10 +590,11 @@ template <class Key, class T>
Q_INLINE_TEMPLATE QHash<Key, T> &QHash<Key, T>::operator=(const QHash<Key, T> &other)
{
if (d != other.d) {
- other.d->ref.ref();
+ QHashData *o = other.d;
+ o->ref.ref();
if (!d->ref.deref())
freeData(d);
- d = other.d;
+ d = o;
if (!d->sharable)
detach_helper();
}
diff --git a/src/corelib/tools/qlinkedlist.h b/src/corelib/tools/qlinkedlist.h
index d145fe3..c087944 100644
--- a/src/corelib/tools/qlinkedlist.h
+++ b/src/corelib/tools/qlinkedlist.h
@@ -85,6 +85,10 @@ public:
inline QLinkedList(const QLinkedList<T> &l) : d(l.d) { d->ref.ref(); if (!d->sharable) detach(); }
~QLinkedList();
QLinkedList<T> &operator=(const QLinkedList<T> &);
+#ifdef Q_COMPILER_RVALUE_REFS
+ inline QLinkedList<T> &operator=(QLinkedList<T> &&other)
+ { qSwap(d, other.d); return *this; }
+#endif
bool operator==(const QLinkedList<T> &l) const;
inline bool operator!=(const QLinkedList<T> &l) const { return !(*this == l); }
@@ -312,10 +316,11 @@ template <typename T>
QLinkedList<T> &QLinkedList<T>::operator=(const QLinkedList<T> &l)
{
if (d != l.d) {
- l.d->ref.ref();
+ QLinkedListData *o = l.d;
+ o->ref.ref();
if (!d->ref.deref())
free(d);
- d = l.d;
+ d = o;
if (!d->sharable)
detach_helper();
}
diff --git a/src/corelib/tools/qlist.h b/src/corelib/tools/qlist.h
index 99c9795..8f988d6 100644
--- a/src/corelib/tools/qlist.h
+++ b/src/corelib/tools/qlist.h
@@ -50,6 +50,10 @@
#include <iterator>
#include <list>
#endif
+#ifdef Q_COMPILER_INITIALIZER_LISTS
+#include <iterator>
+#include <initializer_list>
+#endif
#include <new>
#include <limits.h>
@@ -118,6 +122,14 @@ public:
inline QList(const QList<T> &l) : d(l.d) { d->ref.ref(); if (!d->sharable) detach_helper(); }
~QList();
QList<T> &operator=(const QList<T> &l);
+#ifdef Q_COMPILER_RVALUE_REFS
+ inline QList &operator=(QList &&other)
+ { qSwap(d, other.d); return *this; }
+#endif
+#ifdef Q_COMPILER_INITIALIZER_LISTS
+ inline QList(std::initializer_list<T> args) : d(&QListData::shared_null)
+ { d->ref.ref(); qCopy(args.begin(), args.end(), std::back_inserter(*this)); }
+#endif
bool operator==(const QList<T> &l) const;
inline bool operator!=(const QList<T> &l) const { return !(*this == l); }
@@ -424,10 +436,11 @@ template <typename T>
Q_INLINE_TEMPLATE QList<T> &QList<T>::operator=(const QList<T> &l)
{
if (d != l.d) {
- l.d->ref.ref();
+ QListData::Data *o = l.d;
+ o->ref.ref();
if (!d->ref.deref())
free(d);
- d = l.d;
+ d = o;
if (!d->sharable)
detach_helper();
}
diff --git a/src/corelib/tools/qmap.h b/src/corelib/tools/qmap.h
index 2d11613..ce8fd75 100644
--- a/src/corelib/tools/qmap.h
+++ b/src/corelib/tools/qmap.h
@@ -185,6 +185,10 @@ public:
inline ~QMap() { if (!d) return; if (!d->ref.deref()) freeData(d); }
QMap<Key, T> &operator=(const QMap<Key, T> &other);
+#ifdef Q_COMPILER_RVALUE_REFS
+ inline QMap<Key, T> &operator=(QMap<Key, T> &&other)
+ { qSwap(d, other.d); return *this; }
+#endif
#ifndef QT_NO_STL
explicit QMap(const typename std::map<Key, T> &other);
std::map<Key, T> toStdMap() const;
@@ -424,10 +428,11 @@ template <class Key, class T>
Q_INLINE_TEMPLATE QMap<Key, T> &QMap<Key, T>::operator=(const QMap<Key, T> &other)
{
if (d != other.d) {
- other.d->ref.ref();
+ QMapData* o = other.d;
+ o->ref.ref();
if (!d->ref.deref())
freeData(d);
- d = other.d;
+ d = o;
if (!d->sharable)
detach_helper();
}
diff --git a/src/corelib/tools/qregexp.cpp b/src/corelib/tools/qregexp.cpp
index 36827d0..a0df065 100644
--- a/src/corelib/tools/qregexp.cpp
+++ b/src/corelib/tools/qregexp.cpp
@@ -4172,6 +4172,8 @@ int QRegExp::matchedLength() const
}
#ifndef QT_NO_REGEXP_CAPTURE
+
+#ifndef QT_NO_DEPRECATED
/*!
\obsolete
Returns the number of captures contained in the regular expression.
@@ -4182,6 +4184,7 @@ int QRegExp::numCaptures() const
{
return captureCount();
}
+#endif
/*!
\since 4.6
diff --git a/src/corelib/tools/qregexp.h b/src/corelib/tools/qregexp.h
index e19c130..0b4a702 100644
--- a/src/corelib/tools/qregexp.h
+++ b/src/corelib/tools/qregexp.h
@@ -76,6 +76,10 @@ public:
QRegExp(const QRegExp &rx);
~QRegExp();
QRegExp &operator=(const QRegExp &rx);
+#ifdef Q_COMPILER_RVALUE_REFS
+ inline QRegExp &operator=(QRegExp &&other)
+ { qSwap(priv,other.priv); return *this; }
+#endif
bool operator==(const QRegExp &rx) const;
inline bool operator!=(const QRegExp &rx) const { return !operator==(rx); }
diff --git a/src/corelib/tools/qset.h b/src/corelib/tools/qset.h
index fe50d4d..dc3c45a 100644
--- a/src/corelib/tools/qset.h
+++ b/src/corelib/tools/qset.h
@@ -61,6 +61,10 @@ public:
inline QSet<T> &operator=(const QSet<T> &other)
{ q_hash = other.q_hash; return *this; }
+#ifdef Q_COMPILER_RVALUE_REFS
+ inline QSet<T> &operator=(QSet<T> &&other)
+ { qSwap(q_hash, other.q_hash); return *this; }
+#endif
inline bool operator==(const QSet<T> &other) const
{ return q_hash == other.q_hash; }
diff --git a/src/corelib/tools/qshareddata.h b/src/corelib/tools/qshareddata.h
index 80ba7b7..b646a9d 100644
--- a/src/corelib/tools/qshareddata.h
+++ b/src/corelib/tools/qshareddata.h
@@ -95,9 +95,10 @@ public:
if (o.d != d) {
if (o.d)
o.d->ref.ref();
- if (d && !d->ref.deref())
- delete d;
+ T *old = d;
d = o.d;
+ if (old && !old->ref.deref())
+ delete old;
}
return *this;
}
@@ -105,12 +106,17 @@ public:
if (o != d) {
if (o)
o->ref.ref();
- if (d && !d->ref.deref())
- delete d;
+ T *old = d;
d = o;
+ if (old && !old->ref.deref())
+ delete old;
}
return *this;
}
+#ifdef Q_COMPILER_RVALUE_REFS
+ inline QSharedDataPointer<T> &operator=(QSharedDataPointer<T> &&other)
+ { qSwap(d, other.d); return *this; }
+#endif
inline bool operator!() const { return !d; }
@@ -172,9 +178,10 @@ public:
if (o.d != d) {
if (o.d)
o.d->ref.ref();
- if (d && !d->ref.deref())
- delete d;
+ T *old = d;
d = o.d;
+ if (old && !old->ref.deref())
+ delete old;
}
return *this;
}
@@ -182,12 +189,17 @@ public:
if (o != d) {
if (o)
o->ref.ref();
- if (d && !d->ref.deref())
- delete d;
+ T *old = d;
d = o;
+ if (old && !old->ref.deref())
+ delete old;
}
return *this;
}
+#ifdef Q_COMPILER_RVALUE_REFS
+ inline QSharedDataPointer<T> &operator=(QSharedDataPointer<T> &&other)
+ { qSwap(d, other.d); return *this; }
+#endif
inline bool operator!() const { return !d; }
diff --git a/src/corelib/tools/qsharedpointer_impl.h b/src/corelib/tools/qsharedpointer_impl.h
index bb06f3a..20dda12 100644
--- a/src/corelib/tools/qsharedpointer_impl.h
+++ b/src/corelib/tools/qsharedpointer_impl.h
@@ -465,6 +465,13 @@ public:
BaseClass::internalCopy(other);
return *this;
}
+#ifdef Q_COMPILER_RVALUE_REFS
+ inline QSharedPointer<T> &operator=(QSharedPointer<T> &&other)
+ {
+ QSharedPointer<T>::internalSwap(other);
+ return *this;
+ }
+#endif
template <class X>
inline QSharedPointer(const QSharedPointer<X> &other) : BaseClass(other)
diff --git a/src/corelib/tools/qsimd.cpp b/src/corelib/tools/qsimd.cpp
index 8005d7d..7babf3a 100644
--- a/src/corelib/tools/qsimd.cpp
+++ b/src/corelib/tools/qsimd.cpp
@@ -41,6 +41,7 @@
#include "qsimd_p.h"
#include <QByteArray>
+#include <stdio.h>
#if defined(Q_OS_WINCE)
#include <windows.h>
@@ -50,15 +51,32 @@
#include <intrin.h>
#endif
+#if defined(Q_OS_LINUX) && defined(__arm__)
+#include "private/qcore_unix_p.h"
+
+// the kernel header definitions for HWCAP_*
+// (the ones we need/may need anyway)
+
+// copied from <asm/hwcap.h> (ARM)
+#define HWCAP_IWMMXT 512
+#define HWCAP_CRUNCH 1024
+#define HWCAP_THUMBEE 2048
+#define HWCAP_NEON 4096
+#define HWCAP_VFPv3 8192
+#define HWCAP_VFPv3D16 16384
+
+// copied from <linux/auxvec.h>
+#define AT_HWCAP 16 /* arch dependent hints at CPU capabilities */
+
+#endif
+
QT_BEGIN_NAMESPACE
-uint qDetectCPUFeatures()
+#if defined (Q_OS_WINCE)
+static inline uint detectProcessorFeatures()
{
- static uint features = 0xffffffff;
- if (features != 0xffffffff)
- return features;
+ uint features = 0;
-#if defined (Q_OS_WINCE)
#if defined (ARM)
if (IsProcessorFeaturePresent(PF_ARM_INTEL_WMMX)) {
features = IWMMXT;
@@ -78,77 +96,98 @@ uint qDetectCPUFeatures()
#endif
features = 0;
return features;
-#elif defined(QT_HAVE_IWMMXT)
+}
+
+#elif defined(__arm__) || defined(__arm) || defined(QT_HAVE_IWMMXT) || defined(QT_HAVE_NEON)
+static inline uint detectProcessorFeatures()
+{
+ uint features = 0;
+
+#if defined(Q_OS_LINUX)
+ int auxv = ::qt_safe_open("/proc/self/auxv", O_RDONLY);
+ if (auxv != -1) {
+ unsigned long vector[64];
+ int nread;
+ while (features == 0) {
+ nread = ::qt_safe_read(auxv, (char *)vector, sizeof vector);
+ if (nread <= 0) {
+ // EOF or error
+ break;
+ }
+
+ int max = nread / (sizeof vector[0]);
+ for (int i = 0; i < max; i += 2)
+ if (vector[i] == AT_HWCAP) {
+ if (vector[i+1] & HWCAP_IWMMXT)
+ features |= IWMMXT;
+ if (vector[i+1] & HWCAP_NEON)
+ features |= NEON;
+ break;
+ }
+ }
+
+ ::qt_safe_close(auxv);
+ return features;
+ }
+ // fall back if /proc/self/auxv wasn't found
+#endif
+
+#if defined(QT_HAVE_IWMMXT)
// runtime detection only available when running as a previlegied process
- static const bool doIWMMXT = !qgetenv("QT_NO_IWMMXT").toInt();
- features = doIWMMXT ? IWMMXT : 0;
- return features;
+ features = IWMMXT;
#elif defined(QT_HAVE_NEON)
- static const bool doNEON = !qgetenv("QT_NO_NEON").toInt();
- features = doNEON ? NEON : 0;
+ features = NEON;
+#endif
+
return features;
-#else
- features = 0;
-#if defined(__x86_64__) || defined(Q_OS_WIN64)
- features = MMX|SSE|SSE2|CMOV;
-#elif defined(__ia64__)
- features = MMX|SSE|SSE2;
+}
+
#elif defined(__i386__) || defined(_M_IX86)
+static inline uint detectProcessorFeatures()
+{
+ uint features = 0;
+
unsigned int extended_result = 0;
unsigned int feature_result = 0;
uint result = 0;
/* see p. 118 of amd64 instruction set manual Vol3 */
#if defined(Q_CC_GNU)
- asm ("push %%ebx\n"
- "pushf\n"
- "pop %%eax\n"
- "mov %%eax, %%ebx\n"
- "xor $0x00200000, %%eax\n"
- "push %%eax\n"
+ long cpuid_supported, tmp1;
+ asm ("pushf\n"
+ "pop %0\n"
+ "mov %0, %1\n"
+ "xor $0x00200000, %0\n"
+ "push %0\n"
"popf\n"
"pushf\n"
- "pop %%eax\n"
- "xor %%edx, %%edx\n"
- "xor %%ebx, %%eax\n"
- "jz 1f\n"
-
- "mov $0x00000001, %%eax\n"
- "cpuid\n"
- "1:\n"
- "pop %%ebx\n"
- "mov %%edx, %0\n"
- "mov %%ecx, %1\n"
- : "=r" (result), "=r" (feature_result)
- :
- : "%eax", "%ecx", "%edx"
- );
+ "pop %0\n"
+ "xor %1, %0\n" // %eax is now 0 if CPUID is not supported
+ : "=a" (cpuid_supported), "=r" (tmp1)
+ );
+ if (cpuid_supported) {
+ asm ("xchg %%ebx, %2\n"
+ "cpuid\n"
+ "xchg %%ebx, %2\n"
+ : "=c" (feature_result), "=d" (result), "=&r" (tmp1)
+ : "a" (1));
- asm ("push %%ebx\n"
- "pushf\n"
- "pop %%eax\n"
- "mov %%eax, %%ebx\n"
- "xor $0x00200000, %%eax\n"
- "push %%eax\n"
- "popf\n"
- "pushf\n"
- "pop %%eax\n"
- "xor %%edx, %%edx\n"
- "xor %%ebx, %%eax\n"
- "jz 2f\n"
+ asm ("xchg %%ebx, %1\n"
+ "cpuid\n"
+ "cmp $0x80000000, %%eax\n"
+ "jnbe 1f\n"
+ "xor %0, %0\n"
+ "jmp 2f\n"
+ "1:\n"
+ "mov $0x80000001, %%eax\n"
+ "cpuid\n"
+ "2:\n"
+ "xchg %%ebx, %1\n"
+ : "=d" (extended_result), "=&r" (tmp1)
+ : "a" (0x80000000)
+ : "%ecx"
+ );
+ }
- "mov $0x80000000, %%eax\n"
- "cpuid\n"
- "cmp $0x80000000, %%eax\n"
- "jbe 2f\n"
- "mov $0x80000001, %%eax\n"
- "cpuid\n"
- "2:\n"
- "pop %%ebx\n"
- "mov %%edx, %0\n"
- : "=r" (extended_result)
- :
- : "%eax", "%ecx", "%edx"
- );
#elif defined (Q_OS_WIN)
_asm {
push eax
@@ -210,6 +249,7 @@ uint qDetectCPUFeatures()
}
#endif
+
// result now contains the standard feature bits
if (result & (1u << 15))
features |= CMOV;
@@ -236,33 +276,23 @@ uint qDetectCPUFeatures()
if (feature_result & (1u << 28))
features |= AVX;
-#endif // i386
+ return features;
+}
-#if defined(__x86_64__) || defined(Q_OS_WIN64)
+#elif defined(__x86_64) || defined(Q_OS_WIN64)
+static inline uint detectProcessorFeatures()
+{
+ uint features = MMX|SSE|SSE2|CMOV;
uint feature_result = 0;
#if defined(Q_CC_GNU)
- asm ("push %%rbx\n"
- "pushf\n"
- "pop %%rax\n"
- "mov %%eax, %%ebx\n"
- "xor $0x00200000, %%eax\n"
- "push %%rax\n"
- "popf\n"
- "pushf\n"
- "pop %%rax\n"
- "xor %%edx, %%edx\n"
- "xor %%ebx, %%eax\n"
- "jz 1f\n"
-
- "mov $0x00000001, %%eax\n"
+ long tmp;
+ asm ("xchg %%rbx, %1\n"
"cpuid\n"
- "1:\n"
- "pop %%rbx\n"
- "mov %%ecx, %0\n"
- : "=r" (feature_result)
- :
- : "%eax", "%ecx", "%edx"
+ "xchg %%rbx, %1\n"
+ : "=c" (feature_result), "=&r" (tmp)
+ : "a" (1)
+ : "%edx"
);
#elif defined (Q_OS_WIN64)
{
@@ -282,33 +312,97 @@ uint qDetectCPUFeatures()
features |= SSE4_2;
if (feature_result & (1u << 28))
features |= AVX;
-#endif // x86_64
-#if defined(QT_HAVE_MMX)
- if (qgetenv("QT_NO_MMX").toInt())
- features ^= MMX;
-#endif
- if (qgetenv("QT_NO_MMXEXT").toInt())
- features ^= MMXEXT;
+ return features;
+}
-#if defined(QT_HAVE_3DNOW)
- if (qgetenv("QT_NO_3DNOW").toInt())
- features ^= MMX3DNOW;
-#endif
- if (qgetenv("QT_NO_3DNOWEXT").toInt())
- features ^= MMX3DNOWEXT;
+#elif defined(__ia64__)
+static inline uint detectProcessorFeatures()
+{
+ return MMX|SSE|SSE2;
+}
-#if defined(QT_HAVE_SSE)
- if (qgetenv("QT_NO_SSE").toInt())
- features ^= SSE;
-#endif
-#if defined(QT_HAVE_SSE2)
- if (qgetenv("QT_NO_SSE2").toInt())
- features ^= SSE2;
+#else
+static inline uint detectProcessorFeatures()
+{
+ return 0;
+}
#endif
+/*
+ * Use kdesdk/scripts/generate_string_table.pl to update the table below.
+ * Here's the data (don't forget the ONE leading space):
+ mmx
+ mmxext
+ mmx3dnow
+ mmx3dnowext
+ sse
+ sse2
+ cmov
+ iwmmxt
+ neon
+ sse3
+ ssse3
+ sse4.1
+ sse4.2
+ avx
+ */
+
+// begin generated
+static const char features_string[] =
+ " mmx\0"
+ " mmxext\0"
+ " mmx3dnow\0"
+ " mmx3dnowext\0"
+ " sse\0"
+ " sse2\0"
+ " cmov\0"
+ " iwmmxt\0"
+ " neon\0"
+ " sse3\0"
+ " ssse3\0"
+ " sse4.1\0"
+ " sse4.2\0"
+ " avx\0"
+ "\0";
+
+static const int features_indices[] = {
+ 0, 5, 13, 23, 36, 41, 47, 53,
+ 61, 67, 73, 80, 88, 96, -1
+};
+// end generated
+
+const int features_count = (sizeof features_indices - 1) / (sizeof features_indices[0]);
+
+uint qDetectCPUFeatures()
+{
+ static QBasicAtomicInt features = Q_BASIC_ATOMIC_INITIALIZER(-1);
+ if (features != -1)
+ return features;
+
+ uint f = detectProcessorFeatures();
+ QByteArray disable = qgetenv("QT_NO_CPU_FEATURE");
+ if (!disable.isEmpty()) {
+ disable.prepend(' ');
+ for (int i = 0; i < features_count; ++i) {
+ if (disable.contains(features_string + features_indices[i]))
+ f &= ~(1 << i);
+ }
+ }
+
+ features = f;
return features;
-#endif
+}
+
+void qDumpCPUFeatures()
+{
+ uint features = qDetectCPUFeatures();
+ printf("Processor features: ");
+ for (int i = 0; i < features_count; ++i) {
+ if (features & (1 << i))
+ printf("%s", features_string + features_indices[i]);
+ }
+ puts("");
}
QT_END_NAMESPACE
diff --git a/src/corelib/tools/qsimd_p.h b/src/corelib/tools/qsimd_p.h
index a3148fb..664543b 100644
--- a/src/corelib/tools/qsimd_p.h
+++ b/src/corelib/tools/qsimd_p.h
@@ -51,8 +51,13 @@ QT_BEGIN_HEADER
#if defined(QT_NO_MAC_XARCH) || (defined(Q_OS_DARWIN) && (defined(__ppc__) || defined(__ppc64__)))
// Disable MMX and SSE on Mac/PPC builds, or if the compiler
// does not support -Xarch argument passing
-#undef QT_HAVE_SSE2
#undef QT_HAVE_SSE
+#undef QT_HAVE_SSE2
+#undef QT_HAVE_SSE3
+#undef QT_HAVE_SSSE3
+#undef QT_HAVE_SSE4_1
+#undef QT_HAVE_SSE4_2
+#undef QT_HAVE_AVX
#undef QT_HAVE_3DNOW
#undef QT_HAVE_MMX
#endif
@@ -85,6 +90,7 @@ QT_BEGIN_HEADER
// SSE4.1 and SSE4.2 intrinsics
#if (defined(QT_HAVE_SSE4_1) || defined(QT_HAVE_SSE4_2)) && (defined(__SSE4_1__) || defined(Q_CC_MSVC))
#include <smmintrin.h>
+#include <nmmintrin.h>
#endif
// AVX intrinsics
diff --git a/src/corelib/tools/qstring.cpp b/src/corelib/tools/qstring.cpp
index 7ea9877..7589f59 100644
--- a/src/corelib/tools/qstring.cpp
+++ b/src/corelib/tools/qstring.cpp
@@ -189,19 +189,6 @@ static int ucstricmp(const ushort *a, const ushort *ae, const uchar *b)
return 1;
}
-// Unicode case-insensitive comparison
-static int ucstrcmp(const QChar *a, int alen, const QChar *b, int blen)
-{
- if (a == b && alen == blen)
- return 0;
- int l = qMin(alen, blen);
- while (l-- && *a == *b)
- a++,b++;
- if (l == -1)
- return (alen-blen);
- return a->unicode() - b->unicode();
-}
-
// Unicode case-sensitive compare two same-sized strings
static int ucstrncmp(const QChar *a, const QChar *b, int l)
{
@@ -212,28 +199,71 @@ static int ucstrncmp(const QChar *a, const QChar *b, int l)
return a->unicode() - b->unicode();
}
+// Unicode case-sensitive comparison
+static int ucstrcmp(const QChar *a, int alen, const QChar *b, int blen)
+{
+ if (a == b && alen == blen)
+ return 0;
+ int l = qMin(alen, blen);
+ int cmp = ucstrncmp(a, b, l);
+ return cmp ? cmp : (alen-blen);
+}
+
// Unicode case-insensitive compare two same-sized strings
static int ucstrnicmp(const ushort *a, const ushort *b, int l)
{
return ucstricmp(a, a + l, b, b + l);
}
+// Benchmarking indicates that doing memcmp is much slower than
+// executing the comparison ourselves.
+//
+// The profiling was done on a population of calls to qMemEquals, generated
+// during a run of the demo browser. The profile of the data (32-bit x86
+// Linux) was:
+//
+// total number of comparisons: 21353
+// longest string compared: 95
+// average comparison length: 14.8786
+// cache-line crosses: 5661 (13.3%)
+// alignment histogram:
+// 0xXXX0 = 512 (1.2%) strings, 0 (0.0%) of which same-aligned
+// 0xXXX2 = 15087 (35.3%) strings, 5145 (34.1%) of which same-aligned
+// 0xXXX4 = 525 (1.2%) strings, 0 (0.0%) of which same-aligned
+// 0xXXX6 = 557 (1.3%) strings, 6 (1.1%) of which same-aligned
+// 0xXXX8 = 509 (1.2%) strings, 0 (0.0%) of which same-aligned
+// 0xXXXa = 24358 (57.0%) strings, 9901 (40.6%) of which same-aligned
+// 0xXXXc = 557 (1.3%) strings, 0 (0.0%) of which same-aligned
+// 0xXXXe = 601 (1.4%) strings, 15 (2.5%) of which same-aligned
+// total = 42706 (100%) strings, 15067 (35.3%) of which same-aligned
+//
+// 92% of the strings have alignment of 2 or 10, which is due to malloc on
+// 32-bit Linux returning values aligned to 8 bytes, and offsetof(array, QString::Data) == 18.
+//
+// The profile on 64-bit will be different since offsetof(array, QString::Data) == 26.
+//
+// The benchmark results were, for a Core-i7 @ 2.67 GHz 32-bit, compiled with -O3 -funroll-loops:
+// 16-bit loads only: 872,301 CPU ticks [Qt 4.5 / memcmp]
+// 32- and 16-bit loads: 773,362 CPU ticks [Qt 4.6]
+// SSE2 "movdqu" 128-bit loads: 618,736 CPU ticks
+// SSE3 "lddqu" 128-bit loads: 619,954 CPU ticks
+// SSSE3 "palignr" corrections: 852,147 CPU ticks
+// SSE4.2 "pcmpestrm": 738,702 CPU ticks
+//
+// The same benchmark on an Atom N450 @ 1.66 GHz, is:
+// 16-bit loads only: 2,185,882 CPU ticks
+// 32- and 16-bit loads: 1,805,060 CPU ticks
+// SSE2 "movdqu" 128-bit loads: 2,529,843 CPU ticks
+// SSE3 "lddqu" 128-bit loads: 2,514,858 CPU ticks
+// SSSE3 "palignr" corrections: 2,160,325 CPU ticks
+// SSE4.2 not available
+//
+// The conclusion we reach is that alignment the SSE2 unaligned code can gain
+// 20% improvement in performance in some systems, but suffers a penalty due
+// to the unaligned loads on others.
+
static bool qMemEquals(const quint16 *a, const quint16 *b, int length)
{
- // Benchmarking indicates that doing memcmp is much slower than
- // executing the comparison ourselves.
- // To make it even faster, we do a 32-bit comparison, comparing
- // twice the amount of data as a normal word-by-word comparison.
- //
- // Benchmarking results on a 2.33 GHz Core2 Duo, with a 64-QChar
- // block of data, with 4194304 iterations (per iteration):
- // operation usec cpu ticks
- // memcmp 330 710
- // 16-bit 79 167-171
- // 32-bit aligned 49 105-109
- //
- // Testing also indicates that unaligned 32-bit loads are as
- // performant as 32-bit aligned.
if (a == b || !length)
return true;
@@ -927,6 +957,24 @@ QString QString::fromWCharArray(const wchar_t *string, int size)
\sa utf16(), toAscii(), toLatin1(), toUtf8(), toLocal8Bit()
*/
+template<typename T> int toUcs4_helper(const unsigned short *uc, int length, T *out)
+{
+ int i = 0;
+ for (; i < length; ++i) {
+ uint u = uc[i];
+ if (QChar::isHighSurrogate(u) && i < length-1) {
+ ushort low = uc[i+1];
+ if (QChar::isLowSurrogate(low)) {
+ ++i;
+ u = QChar::surrogateToUcs4(u, low);
+ }
+ }
+ *out = T(u);
+ ++out;
+ }
+ return i;
+}
+
/*!
\since 4.2
@@ -951,21 +999,7 @@ int QString::toWCharArray(wchar_t *array) const
memcpy(array, utf16(), sizeof(wchar_t)*length());
return length();
} else {
- wchar_t *a = array;
- const unsigned short *uc = utf16();
- for (int i = 0; i < length(); ++i) {
- uint u = uc[i];
- if (QChar::isHighSurrogate(u) && i + 1 < length()) {
- ushort low = uc[i+1];
- if (QChar::isLowSurrogate(low)) {
- u = QChar::surrogateToUcs4(u, low);
- ++i;
- }
- }
- *a = wchar_t(u);
- ++a;
- }
- return a - array;
+ return toUcs4_helper<wchar_t>(utf16(), length(), array);
}
}
@@ -3701,7 +3735,7 @@ QByteArray QString::toUtf8() const
Returns a UCS-4/UTF-32 representation of the string as a QVector<uint>.
UCS-4 is a Unicode codec and is lossless. All characters from this string
- can be encoded in UCS-4.
+ can be encoded in UCS-4. The vector is not null terminated.
\sa fromUtf8(), toAscii(), toLatin1(), toLocal8Bit(), QTextCodec, fromUcs4(), toWCharArray()
*/
@@ -3709,20 +3743,8 @@ QVector<uint> QString::toUcs4() const
{
QVector<uint> v(length());
uint *a = v.data();
- const unsigned short *uc = utf16();
- for (int i = 0; i < length(); ++i) {
- uint u = uc[i];
- if (QChar(u).isHighSurrogate() && i < length()-1) {
- ushort low = uc[i+1];
- if (QChar(low).isLowSurrogate()) {
- ++i;
- u = QChar::surrogateToUcs4(u, low);
- }
- }
- *a = u;
- ++a;
- }
- v.resize(a - v.data());
+ int len = toUcs4_helper<uint>(utf16(), length(), a);
+ v.resize(len);
return v;
}
@@ -3943,8 +3965,8 @@ QString QString::fromUtf8(const char *str, int size)
This function checks for a Byte Order Mark (BOM). If it is missing,
host byte order is assumed.
- This function is comparatively slow.
- Use QString(const ushort *, int) or QString(const ushort *) if possible.
+ This function is slow compared to the other Unicode conversions.
+ Use QString(const QChar *, int) or QString(const QChar *) if possible.
QString makes a deep copy of the Unicode data.
@@ -8961,4 +8983,114 @@ static inline bool qt_ends_with(const QChar *haystack, int haystackLen,
return true;
}
+/*!
+ \since 4.8
+
+ Returns a Latin-1 representation of the string as a QByteArray.
+
+ The returned byte array is undefined if the string contains non-Latin1
+ characters. Those characters may be suppressed or replaced with a
+ question mark.
+
+ \sa toAscii(), toUtf8(), toLocal8Bit(), QTextCodec
+*/
+QByteArray QStringRef::toLatin1() const
+{
+ return toLatin1_helper(unicode(), length());
+}
+
+/*!
+ \since 4.8
+
+ Returns an 8-bit representation of the string as a QByteArray.
+
+ If a codec has been set using QTextCodec::setCodecForCStrings(),
+ it is used to convert Unicode to 8-bit char; otherwise this
+ function does the same as toLatin1().
+
+ Note that, despite the name, this function does not necessarily return an US-ASCII
+ (ANSI X3.4-1986) string and its result may not be US-ASCII compatible.
+
+ \sa toLatin1(), toUtf8(), toLocal8Bit(), QTextCodec
+*/
+QByteArray QStringRef::toAscii() const
+{
+#ifndef QT_NO_TEXTCODEC
+ if (QString::codecForCStrings)
+ return QString::codecForCStrings->fromUnicode(unicode(), length());
+#endif // QT_NO_TEXTCODEC
+ return toLatin1();
+}
+
+/*!
+ \since 4.8
+
+ Returns the local 8-bit representation of the string as a
+ QByteArray. The returned byte array is undefined if the string
+ contains characters not supported by the local 8-bit encoding.
+
+ QTextCodec::codecForLocale() is used to perform the conversion from
+ Unicode. If the locale encoding could not be determined, this function
+ does the same as toLatin1().
+
+ If this string contains any characters that cannot be encoded in the
+ locale, the returned byte array is undefined. Those characters may be
+ suppressed or replaced by another.
+
+ \sa toAscii(), toLatin1(), toUtf8(), QTextCodec
+*/
+QByteArray QStringRef::toLocal8Bit() const
+{
+#ifndef QT_NO_TEXTCODEC
+ if (QTextCodec::codecForLocale())
+ return QTextCodec::codecForLocale()->fromUnicode(unicode(), length());
+#endif // QT_NO_TEXTCODEC
+ return toLatin1();
+}
+
+/*!
+ \since 4.8
+
+ Returns a UTF-8 representation of the string as a QByteArray.
+
+ UTF-8 is a Unicode codec and can represent all characters in a Unicode
+ string like QString.
+
+ However, in the Unicode range, there are certain codepoints that are not
+ considered characters. The Unicode standard reserves the last two
+ codepoints in each Unicode Plane (U+FFFE, U+FFFF, U+1FFFE, U+1FFFF,
+ U+2FFFE, etc.), as well as 16 codepoints in the range U+FDD0..U+FDDF,
+ inclusive, as non-characters. If any of those appear in the string, they
+ may be discarded and will not appear in the UTF-8 representation, or they
+ may be replaced by one or more replacement characters.
+
+ \sa toAscii(), toLatin1(), toLocal8Bit(), QTextCodec
+*/
+QByteArray QStringRef::toUtf8() const
+{
+ if (isNull())
+ return QByteArray();
+
+ return QUtf8::convertFromUnicode(constData(), length(), 0);
+}
+
+/*!
+ \since 4.8
+
+ Returns a UCS-4/UTF-32 representation of the string as a QVector<uint>.
+
+ UCS-4 is a Unicode codec and is lossless. All characters from this string
+ can be encoded in UCS-4.
+
+ \sa fromUtf8(), toAscii(), toLatin1(), toLocal8Bit(), QTextCodec, fromUcs4(), toWCharArray()
+*/
+QVector<uint> QStringRef::toUcs4() const
+{
+ QVector<uint> v(length());
+ uint *a = v.data();
+ int len = toUcs4_helper<uint>(reinterpret_cast<const unsigned short *>(unicode()), length(), a);
+ v.resize(len);
+ return v;
+}
+
QT_END_NAMESPACE
diff --git a/src/corelib/tools/qstring.h b/src/corelib/tools/qstring.h
index 7f7e475..589fdc2 100644
--- a/src/corelib/tools/qstring.h
+++ b/src/corelib/tools/qstring.h
@@ -104,7 +104,10 @@ public:
QString &operator=(QChar c);
QString &operator=(const QString &);
inline QString &operator=(const QLatin1String &);
-
+#ifdef Q_COMPILER_RVALUE_REFS
+ inline QString &operator=(QString &&other)
+ { qSwap(d, other.d); return *this; }
+#endif
inline int size() const { return d->size; }
inline int count() const { return d->size; }
inline int length() const;
@@ -613,6 +616,7 @@ private:
ushort asciiCache : 1;
ushort capacity : 1;
ushort reserved : 11;
+ // ### Qt5: try to ensure that "array" is aligned to 16 bytes on both 32- and 64-bit
ushort array[1];
};
static Data shared_null;
@@ -1161,6 +1165,12 @@ public:
inline const QChar *data() const { return unicode(); }
inline const QChar *constData() const { return unicode(); }
+ QByteArray toAscii() const Q_REQUIRED_RESULT;
+ QByteArray toLatin1() const Q_REQUIRED_RESULT;
+ QByteArray toUtf8() const Q_REQUIRED_RESULT;
+ QByteArray toLocal8Bit() const Q_REQUIRED_RESULT;
+ QVector<uint> toUcs4() const Q_REQUIRED_RESULT;
+
inline void clear() { m_string = 0; m_position = m_size = 0; }
QString toString() const;
inline bool isEmpty() const { return m_size == 0; }
diff --git a/src/corelib/tools/qstringmatcher.cpp b/src/corelib/tools/qstringmatcher.cpp
index 80a8457..d445ed4 100644
--- a/src/corelib/tools/qstringmatcher.cpp
+++ b/src/corelib/tools/qstringmatcher.cpp
@@ -40,7 +40,6 @@
****************************************************************************/
#include "qstringmatcher.h"
-#include "qunicodetables_p.h"
QT_BEGIN_NAMESPACE
diff --git a/src/corelib/tools/qunicodetables.cpp b/src/corelib/tools/qunicodetables.cpp
index 9df31e5..68e72cc 100644
--- a/src/corelib/tools/qunicodetables.cpp
+++ b/src/corelib/tools/qunicodetables.cpp
@@ -4345,6 +4345,11 @@ Q_CORE_EXPORT const QUnicodeTables::Properties * QT_FASTCALL QUnicodeTables::pro
return uc_properties + index;
}
+Q_CORE_EXPORT QUnicodeTables::LineBreakClass QT_FASTCALL QUnicodeTables::lineBreakClass(uint ucs4)
+{
+ return (QUnicodeTables::LineBreakClass)qGetProp(ucs4)->line_break_class;
+}
+
static const ushort specialCaseMap[] = {
0x53, 0x73, 0x0,
0x53, 0x53, 0x0,
@@ -8561,7 +8566,7 @@ static const unsigned char uc_scripts[] = {
Inherited, Inherited, Inherited, Inherited, Inherited, Inherited, Inherited, Inherited,
Inherited, Inherited, Inherited, Inherited, Inherited, Inherited, Inherited, Inherited,
Common, Common, Common, Common, Greek, Greek, Common, Common,
- Common, Common, Greek, Greek, Greek, Greek, Common, Common,
+ Common, Common, Greek, Greek, Greek, Greek, Common, Common,
/* U+0380-03ff at offset 640 */
Common, Common, Common, Common, Greek, Greek, Greek, Common,
@@ -8579,7 +8584,7 @@ static const unsigned char uc_scripts[] = {
Greek, Greek, Coptic, Coptic, Coptic, Coptic, Coptic, Coptic,
Coptic, Coptic, Coptic, Coptic, Coptic, Coptic, Coptic, Coptic,
Greek, Greek, Greek, Greek, Greek, Greek, Greek, Greek,
- Greek, Greek, Greek, Greek, Greek, Greek, Greek, Greek,
+ Greek, Greek, Greek, Greek, Greek, Greek, Greek, Greek,
/* U+0480-04ff at offset 768 */
Cyrillic, Cyrillic, Cyrillic, Cyrillic, Cyrillic, Cyrillic, Cyrillic, Common,
@@ -8597,7 +8602,7 @@ static const unsigned char uc_scripts[] = {
Cyrillic, Cyrillic, Cyrillic, Cyrillic, Cyrillic, Cyrillic, Cyrillic, Cyrillic,
Cyrillic, Cyrillic, Cyrillic, Cyrillic, Cyrillic, Cyrillic, Cyrillic, Cyrillic,
Cyrillic, Cyrillic, Cyrillic, Cyrillic, Cyrillic, Cyrillic, Cyrillic, Cyrillic,
- Cyrillic, Cyrillic, Cyrillic, Cyrillic, Cyrillic, Cyrillic, Cyrillic, Cyrillic,
+ Cyrillic, Cyrillic, Cyrillic, Cyrillic, Cyrillic, Cyrillic, Cyrillic, Cyrillic,
/* U+0500-057f at offset 896 */
Cyrillic, Cyrillic, Cyrillic, Cyrillic, Cyrillic, Cyrillic, Cyrillic, Cyrillic,
@@ -8615,7 +8620,7 @@ static const unsigned char uc_scripts[] = {
Common, Armenian, Armenian, Armenian, Armenian, Armenian, Armenian, Armenian,
Armenian, Armenian, Armenian, Armenian, Armenian, Armenian, Armenian, Armenian,
Armenian, Armenian, Armenian, Armenian, Armenian, Armenian, Armenian, Armenian,
- Armenian, Armenian, Armenian, Armenian, Armenian, Armenian, Armenian, Armenian,
+ Armenian, Armenian, Armenian, Armenian, Armenian, Armenian, Armenian, Armenian,
/* U+0580-05ff at offset 1024 */
Armenian, Armenian, Armenian, Armenian, Armenian, Armenian, Armenian, Armenian,
@@ -8633,7 +8638,7 @@ static const unsigned char uc_scripts[] = {
Hebrew, Hebrew, Hebrew, Hebrew, Hebrew, Hebrew, Hebrew, Hebrew,
Hebrew, Hebrew, Hebrew, Common, Common, Common, Common, Common,
Hebrew, Hebrew, Hebrew, Hebrew, Hebrew, Common, Common, Common,
- Common, Common, Common, Common, Common, Common, Common, Common,
+ Common, Common, Common, Common, Common, Common, Common, Common,
/* U+0600-067f at offset 1152 */
Common, Common, Common, Common, Common, Common, Common, Common,
@@ -8651,7 +8656,7 @@ static const unsigned char uc_scripts[] = {
Common, Common, Common, Common, Common, Common, Common, Common,
Common, Common, Arabic, Arabic, Arabic, Arabic, Arabic, Arabic,
Inherited, Arabic, Arabic, Arabic, Arabic, Arabic, Arabic, Arabic,
- Arabic, Arabic, Arabic, Arabic, Arabic, Arabic, Arabic, Arabic,
+ Arabic, Arabic, Arabic, Arabic, Arabic, Arabic, Arabic, Arabic,
/* U+0680-06ff at offset 1280 */
Arabic, Arabic, Arabic, Arabic, Arabic, Arabic, Arabic, Arabic,
@@ -8669,7 +8674,7 @@ static const unsigned char uc_scripts[] = {
Arabic, Arabic, Arabic, Arabic, Arabic, Arabic, Arabic, Arabic,
Arabic, Arabic, Arabic, Arabic, Arabic, Arabic, Arabic, Arabic,
Arabic, Arabic, Arabic, Arabic, Arabic, Arabic, Arabic, Arabic,
- Arabic, Arabic, Arabic, Arabic, Arabic, Arabic, Arabic, Arabic,
+ Arabic, Arabic, Arabic, Arabic, Arabic, Arabic, Arabic, Arabic,
/* U+0700-077f at offset 1408 */
Syriac, Syriac, Syriac, Syriac, Syriac, Syriac, Syriac, Syriac,
@@ -8687,7 +8692,7 @@ static const unsigned char uc_scripts[] = {
Arabic, Arabic, Arabic, Arabic, Arabic, Arabic, Arabic, Arabic,
Arabic, Arabic, Arabic, Arabic, Arabic, Arabic, Common, Common,
Common, Common, Common, Common, Common, Common, Common, Common,
- Common, Common, Common, Common, Common, Common, Common, Common,
+ Common, Common, Common, Common, Common, Common, Common, Common,
/* U+0780-07ff at offset 1536 */
Thaana, Thaana, Thaana, Thaana, Thaana, Thaana, Thaana, Thaana,
@@ -8705,7 +8710,7 @@ static const unsigned char uc_scripts[] = {
Nko, Nko, Nko, Nko, Nko, Nko, Nko, Nko,
Nko, Nko, Nko, Nko, Nko, Nko, Nko, Nko,
Nko, Nko, Nko, Nko, Nko, Nko, Nko, Nko,
- Nko, Nko, Nko, Common, Common, Common, Common, Common,
+ Nko, Nko, Nko, Common, Common, Common, Common, Common,
/* U+0900-097f at offset 1664 */
Common, Devanagari, Devanagari, Devanagari, Devanagari, Devanagari, Devanagari, Devanagari,
@@ -8723,7 +8728,7 @@ static const unsigned char uc_scripts[] = {
Devanagari, Devanagari, Devanagari, Devanagari, Common, Common, Devanagari, Devanagari,
Devanagari, Devanagari, Devanagari, Devanagari, Devanagari, Devanagari, Devanagari, Devanagari,
Common, Common, Common, Common, Common, Common, Common, Common,
- Common, Common, Common, Devanagari, Devanagari, Devanagari, Devanagari, Devanagari,
+ Common, Common, Common, Devanagari, Devanagari, Devanagari, Devanagari, Devanagari,
/* U+0980-09ff at offset 1792 */
Common, Bengali, Bengali, Bengali, Common, Bengali, Bengali, Bengali,
@@ -8741,7 +8746,7 @@ static const unsigned char uc_scripts[] = {
Bengali, Bengali, Bengali, Bengali, Common, Common, Bengali, Bengali,
Bengali, Bengali, Bengali, Bengali, Bengali, Bengali, Bengali, Bengali,
Bengali, Bengali, Bengali, Bengali, Bengali, Bengali, Bengali, Bengali,
- Bengali, Bengali, Bengali, Common, Common, Common, Common, Common,
+ Bengali, Bengali, Bengali, Common, Common, Common, Common, Common,
/* U+0a00-0a7f at offset 1920 */
Common, Gurmukhi, Gurmukhi, Gurmukhi, Common, Gurmukhi, Gurmukhi, Gurmukhi,
@@ -8759,7 +8764,7 @@ static const unsigned char uc_scripts[] = {
Common, Common, Common, Common, Common, Common, Gurmukhi, Gurmukhi,
Gurmukhi, Gurmukhi, Gurmukhi, Gurmukhi, Gurmukhi, Gurmukhi, Gurmukhi, Gurmukhi,
Gurmukhi, Gurmukhi, Gurmukhi, Gurmukhi, Gurmukhi, Common, Common, Common,
- Common, Common, Common, Common, Common, Common, Common, Common,
+ Common, Common, Common, Common, Common, Common, Common, Common,
/* U+0a80-0aff at offset 2048 */
Common, Gujarati, Gujarati, Gujarati, Common, Gujarati, Gujarati, Gujarati,
@@ -8777,7 +8782,7 @@ static const unsigned char uc_scripts[] = {
Gujarati, Gujarati, Gujarati, Gujarati, Common, Common, Gujarati, Gujarati,
Gujarati, Gujarati, Gujarati, Gujarati, Gujarati, Gujarati, Gujarati, Gujarati,
Common, Gujarati, Common, Common, Common, Common, Common, Common,
- Common, Common, Common, Common, Common, Common, Common, Common,
+ Common, Common, Common, Common, Common, Common, Common, Common,
/* U+0b00-0b7f at offset 2176 */
Common, Oriya, Oriya, Oriya, Common, Oriya, Oriya, Oriya,
@@ -8795,7 +8800,7 @@ static const unsigned char uc_scripts[] = {
Oriya, Oriya, Common, Common, Common, Common, Oriya, Oriya,
Oriya, Oriya, Oriya, Oriya, Oriya, Oriya, Oriya, Oriya,
Oriya, Oriya, Common, Common, Common, Common, Common, Common,
- Common, Common, Common, Common, Common, Common, Common, Common,
+ Common, Common, Common, Common, Common, Common, Common, Common,
/* U+0b80-0bff at offset 2304 */
Common, Common, Tamil, Tamil, Common, Tamil, Tamil, Tamil,
@@ -8813,7 +8818,7 @@ static const unsigned char uc_scripts[] = {
Common, Common, Common, Common, Common, Common, Tamil, Tamil,
Tamil, Tamil, Tamil, Tamil, Tamil, Tamil, Tamil, Tamil,
Tamil, Tamil, Tamil, Tamil, Tamil, Tamil, Tamil, Tamil,
- Tamil, Tamil, Tamil, Common, Common, Common, Common, Common,
+ Tamil, Tamil, Tamil, Common, Common, Common, Common, Common,
/* U+0c00-0c7f at offset 2432 */
Common, Telugu, Telugu, Telugu, Common, Telugu, Telugu, Telugu,
@@ -8831,7 +8836,7 @@ static const unsigned char uc_scripts[] = {
Telugu, Telugu, Common, Common, Common, Common, Telugu, Telugu,
Telugu, Telugu, Telugu, Telugu, Telugu, Telugu, Telugu, Telugu,
Common, Common, Common, Common, Common, Common, Common, Common,
- Common, Common, Common, Common, Common, Common, Common, Common,
+ Common, Common, Common, Common, Common, Common, Common, Common,
/* U+0c80-0cff at offset 2560 */
Common, Common, Kannada, Kannada, Common, Kannada, Kannada, Kannada,
@@ -8849,7 +8854,7 @@ static const unsigned char uc_scripts[] = {
Kannada, Kannada, Kannada, Kannada, Common, Common, Kannada, Kannada,
Kannada, Kannada, Kannada, Kannada, Kannada, Kannada, Kannada, Kannada,
Common, Kannada, Kannada, Common, Common, Common, Common, Common,
- Common, Common, Common, Common, Common, Common, Common, Common,
+ Common, Common, Common, Common, Common, Common, Common, Common,
/* U+0d00-0d7f at offset 2688 */
Common, Common, Malayalam, Malayalam, Common, Malayalam, Malayalam, Malayalam,
@@ -8867,7 +8872,7 @@ static const unsigned char uc_scripts[] = {
Malayalam, Malayalam, Common, Common, Common, Common, Malayalam, Malayalam,
Malayalam, Malayalam, Malayalam, Malayalam, Malayalam, Malayalam, Malayalam, Malayalam,
Common, Common, Common, Common, Common, Common, Common, Common,
- Common, Common, Common, Common, Common, Common, Common, Common,
+ Common, Common, Common, Common, Common, Common, Common, Common,
/* U+0d80-0dff at offset 2816 */
Common, Common, Sinhala, Sinhala, Common, Sinhala, Sinhala, Sinhala,
@@ -8885,7 +8890,7 @@ static const unsigned char uc_scripts[] = {
Common, Common, Common, Common, Common, Common, Common, Common,
Common, Common, Common, Common, Common, Common, Common, Common,
Common, Common, Sinhala, Sinhala, Sinhala, Common, Common, Common,
- Common, Common, Common, Common, Common, Common, Common, Common,
+ Common, Common, Common, Common, Common, Common, Common, Common,
/* U+0e00-0e7f at offset 2944 */
Common, Thai, Thai, Thai, Thai, Thai, Thai, Thai,
@@ -8903,7 +8908,7 @@ static const unsigned char uc_scripts[] = {
Common, Common, Common, Common, Common, Common, Common, Common,
Common, Common, Common, Common, Common, Common, Common, Common,
Common, Common, Common, Common, Common, Common, Common, Common,
- Common, Common, Common, Common, Common, Common, Common, Common,
+ Common, Common, Common, Common, Common, Common, Common, Common,
/* U+0e80-0eff at offset 3072 */
Common, Lao, Lao, Common, Lao, Common, Common, Lao,
@@ -8921,7 +8926,7 @@ static const unsigned char uc_scripts[] = {
Common, Common, Common, Common, Common, Common, Common, Common,
Common, Common, Common, Common, Common, Common, Common, Common,
Common, Common, Common, Common, Common, Common, Common, Common,
- Common, Common, Common, Common, Common, Common, Common, Common,
+ Common, Common, Common, Common, Common, Common, Common, Common,
/* U+0f00-0f7f at offset 3200 */
Tibetan, Tibetan, Tibetan, Tibetan, Tibetan, Tibetan, Tibetan, Tibetan,
@@ -8939,7 +8944,7 @@ static const unsigned char uc_scripts[] = {
Tibetan, Tibetan, Tibetan, Tibetan, Tibetan, Tibetan, Tibetan, Tibetan,
Tibetan, Tibetan, Tibetan, Common, Common, Common, Common, Common,
Common, Tibetan, Tibetan, Tibetan, Tibetan, Tibetan, Tibetan, Tibetan,
- Tibetan, Tibetan, Tibetan, Tibetan, Tibetan, Tibetan, Tibetan, Tibetan,
+ Tibetan, Tibetan, Tibetan, Tibetan, Tibetan, Tibetan, Tibetan, Tibetan,
/* U+0f80-0fff at offset 3328 */
Tibetan, Tibetan, Tibetan, Tibetan, Tibetan, Tibetan, Tibetan, Tibetan,
@@ -8957,7 +8962,7 @@ static const unsigned char uc_scripts[] = {
Common, Common, Common, Common, Common, Common, Common, Common,
Common, Common, Common, Common, Common, Common, Common, Common,
Common, Common, Common, Common, Common, Common, Common, Common,
- Common, Common, Common, Common, Common, Common, Common, Common,
+ Common, Common, Common, Common, Common, Common, Common, Common,
/* U+1000-107f at offset 3456 */
Myanmar, Myanmar, Myanmar, Myanmar, Myanmar, Myanmar, Myanmar, Myanmar,
@@ -8975,7 +8980,7 @@ static const unsigned char uc_scripts[] = {
Common, Common, Common, Common, Common, Common, Common, Common,
Common, Common, Common, Common, Common, Common, Common, Common,
Common, Common, Common, Common, Common, Common, Common, Common,
- Common, Common, Common, Common, Common, Common, Common, Common,
+ Common, Common, Common, Common, Common, Common, Common, Common,
/* U+1080-10ff at offset 3584 */
Common, Common, Common, Common, Common, Common, Common, Common,
@@ -8993,7 +8998,7 @@ static const unsigned char uc_scripts[] = {
Georgian, Georgian, Georgian, Georgian, Georgian, Georgian, Georgian, Georgian,
Georgian, Georgian, Georgian, Georgian, Georgian, Georgian, Georgian, Georgian,
Georgian, Georgian, Georgian, Georgian, Georgian, Georgian, Georgian, Georgian,
- Georgian, Georgian, Georgian, Common, Georgian, Common, Common, Common,
+ Georgian, Georgian, Georgian, Common, Georgian, Common, Common, Common,
/* U+1100-117f at offset 3712 */
Hangul, Hangul, Hangul, Hangul, Hangul, Hangul, Hangul, Hangul,
@@ -9011,7 +9016,7 @@ static const unsigned char uc_scripts[] = {
Hangul, Hangul, Hangul, Hangul, Hangul, Hangul, Hangul, Hangul,
Hangul, Hangul, Hangul, Hangul, Hangul, Hangul, Hangul, Hangul,
Hangul, Hangul, Hangul, Hangul, Hangul, Hangul, Hangul, Hangul,
- Hangul, Hangul, Hangul, Hangul, Hangul, Hangul, Hangul, Hangul,
+ Hangul, Hangul, Hangul, Hangul, Hangul, Hangul, Hangul, Hangul,
/* U+1180-11ff at offset 3840 */
Hangul, Hangul, Hangul, Hangul, Hangul, Hangul, Hangul, Hangul,
@@ -9029,7 +9034,7 @@ static const unsigned char uc_scripts[] = {
Hangul, Hangul, Hangul, Hangul, Hangul, Hangul, Hangul, Hangul,
Hangul, Hangul, Hangul, Hangul, Hangul, Hangul, Hangul, Hangul,
Hangul, Hangul, Hangul, Hangul, Hangul, Hangul, Hangul, Hangul,
- Hangul, Hangul, Common, Common, Common, Common, Common, Common,
+ Hangul, Hangul, Common, Common, Common, Common, Common, Common,
/* U+1680-16ff at offset 3968 */
Ogham, Ogham, Ogham, Ogham, Ogham, Ogham, Ogham, Ogham,
@@ -9047,7 +9052,7 @@ static const unsigned char uc_scripts[] = {
Runic, Runic, Runic, Runic, Runic, Runic, Runic, Runic,
Runic, Runic, Runic, Common, Common, Common, Runic, Runic,
Runic, Common, Common, Common, Common, Common, Common, Common,
- Common, Common, Common, Common, Common, Common, Common, Common,
+ Common, Common, Common, Common, Common, Common, Common, Common,
/* U+1780-17ff at offset 4096 */
Khmer, Khmer, Khmer, Khmer, Khmer, Khmer, Khmer, Khmer,
@@ -9065,7 +9070,7 @@ static const unsigned char uc_scripts[] = {
Khmer, Khmer, Khmer, Khmer, Khmer, Khmer, Khmer, Khmer,
Khmer, Khmer, Common, Common, Common, Common, Common, Common,
Khmer, Khmer, Khmer, Khmer, Khmer, Khmer, Khmer, Khmer,
- Khmer, Khmer, Common, Common, Common, Common, Common, Common,
+ Khmer, Khmer, Common, Common, Common, Common, Common, Common,
/* U+1980-19ff at offset 4224 */
NewTaiLue, NewTaiLue, NewTaiLue, NewTaiLue, NewTaiLue, NewTaiLue, NewTaiLue, NewTaiLue,
@@ -9083,7 +9088,7 @@ static const unsigned char uc_scripts[] = {
Khmer, Khmer, Khmer, Khmer, Khmer, Khmer, Khmer, Khmer,
Khmer, Khmer, Khmer, Khmer, Khmer, Khmer, Khmer, Khmer,
Khmer, Khmer, Khmer, Khmer, Khmer, Khmer, Khmer, Khmer,
- Khmer, Khmer, Khmer, Khmer, Khmer, Khmer, Khmer, Khmer,
+ Khmer, Khmer, Khmer, Khmer, Khmer, Khmer, Khmer, Khmer,
/* U+1d00-1d7f at offset 4352 */
Latin, Latin, Latin, Latin, Latin, Latin, Latin, Latin,
@@ -9101,7 +9106,7 @@ static const unsigned char uc_scripts[] = {
Greek, Greek, Latin, Latin, Latin, Latin, Greek, Greek,
Greek, Greek, Greek, Latin, Latin, Latin, Latin, Latin,
Latin, Latin, Latin, Latin, Latin, Latin, Latin, Latin,
- Cyrillic, Latin, Latin, Latin, Latin, Latin, Latin, Latin,
+ Cyrillic, Latin, Latin, Latin, Latin, Latin, Latin, Latin,
/* U+1d80-1dff at offset 4480 */
Latin, Latin, Latin, Latin, Latin, Latin, Latin, Latin,
@@ -9119,7 +9124,7 @@ static const unsigned char uc_scripts[] = {
Common, Common, Common, Common, Common, Common, Common, Common,
Common, Common, Common, Common, Common, Common, Common, Common,
Common, Common, Common, Common, Common, Common, Common, Common,
- Common, Common, Common, Common, Common, Common, Inherited, Inherited,
+ Common, Common, Common, Common, Common, Common, Inherited, Inherited,
/* U+1f00-1f7f at offset 4608 */
Greek, Greek, Greek, Greek, Greek, Greek, Greek, Greek,
@@ -9137,7 +9142,7 @@ static const unsigned char uc_scripts[] = {
Greek, Greek, Greek, Greek, Greek, Greek, Greek, Greek,
Greek, Greek, Greek, Greek, Greek, Greek, Greek, Greek,
Greek, Greek, Greek, Greek, Greek, Greek, Greek, Greek,
- Greek, Greek, Greek, Greek, Greek, Greek, Common, Common,
+ Greek, Greek, Greek, Greek, Greek, Greek, Common, Common,
/* U+1f80-1fff at offset 4736 */
Greek, Greek, Greek, Greek, Greek, Greek, Greek, Greek,
@@ -9155,7 +9160,7 @@ static const unsigned char uc_scripts[] = {
Greek, Greek, Greek, Greek, Greek, Greek, Greek, Greek,
Greek, Greek, Greek, Greek, Greek, Greek, Greek, Greek,
Common, Common, Greek, Greek, Greek, Common, Greek, Greek,
- Greek, Greek, Greek, Greek, Greek, Greek, Greek, Common,
+ Greek, Greek, Greek, Greek, Greek, Greek, Greek, Common,
/* U+2000-207f at offset 4864 */
Common, Common, Common, Common, Common, Common, Common, Common,
@@ -9173,7 +9178,7 @@ static const unsigned char uc_scripts[] = {
Common, Common, Common, Common, Common, Common, Common, Common,
Common, Common, Common, Common, Common, Common, Common, Common,
Common, Latin, Common, Common, Common, Common, Common, Common,
- Common, Common, Common, Common, Common, Common, Common, Latin,
+ Common, Common, Common, Common, Common, Common, Common, Latin,
/* U+2080-20ff at offset 4992 */
Common, Common, Common, Common, Common, Common, Common, Common,
@@ -9191,7 +9196,7 @@ static const unsigned char uc_scripts[] = {
Inherited, Inherited, Inherited, Inherited, Inherited, Inherited, Inherited, Inherited,
Inherited, Inherited, Inherited, Inherited, Inherited, Inherited, Inherited, Inherited,
Common, Common, Common, Common, Common, Common, Common, Common,
- Common, Common, Common, Common, Common, Common, Common, Common,
+ Common, Common, Common, Common, Common, Common, Common, Common,
/* U+2100-217f at offset 5120 */
Common, Common, Common, Common, Common, Common, Common, Common,
@@ -9209,7 +9214,7 @@ static const unsigned char uc_scripts[] = {
Common, Common, Common, Common, Common, Common, Common, Common,
Common, Common, Common, Common, Common, Common, Common, Common,
Common, Common, Common, Common, Common, Common, Common, Common,
- Common, Common, Common, Common, Common, Common, Common, Common,
+ Common, Common, Common, Common, Common, Common, Common, Common,
/* U+2d00-2d7f at offset 5248 */
Georgian, Georgian, Georgian, Georgian, Georgian, Georgian, Georgian, Georgian,
@@ -9227,7 +9232,7 @@ static const unsigned char uc_scripts[] = {
Tifinagh, Tifinagh, Tifinagh, Tifinagh, Tifinagh, Tifinagh, Common, Common,
Common, Common, Common, Common, Common, Common, Common, Tifinagh,
Common, Common, Common, Common, Common, Common, Common, Common,
- Common, Common, Common, Common, Common, Common, Common, Common,
+ Common, Common, Common, Common, Common, Common, Common, Common,
/* U+3000-307f at offset 5376 */
Common, Common, Common, Common, Common, Han, Common, Han,
@@ -9245,7 +9250,7 @@ static const unsigned char uc_scripts[] = {
Hiragana, Hiragana, Hiragana, Hiragana, Hiragana, Hiragana, Hiragana, Hiragana,
Hiragana, Hiragana, Hiragana, Hiragana, Hiragana, Hiragana, Hiragana, Hiragana,
Hiragana, Hiragana, Hiragana, Hiragana, Hiragana, Hiragana, Hiragana, Hiragana,
- Hiragana, Hiragana, Hiragana, Hiragana, Hiragana, Hiragana, Hiragana, Hiragana,
+ Hiragana, Hiragana, Hiragana, Hiragana, Hiragana, Hiragana, Hiragana, Hiragana,
/* U+3080-30ff at offset 5504 */
Hiragana, Hiragana, Hiragana, Hiragana, Hiragana, Hiragana, Hiragana, Hiragana,
@@ -9263,7 +9268,7 @@ static const unsigned char uc_scripts[] = {
Katakana, Katakana, Katakana, Katakana, Katakana, Katakana, Katakana, Katakana,
Katakana, Katakana, Katakana, Katakana, Katakana, Katakana, Katakana, Katakana,
Katakana, Katakana, Katakana, Katakana, Katakana, Katakana, Katakana, Katakana,
- Katakana, Katakana, Katakana, Common, Common, Katakana, Katakana, Katakana,
+ Katakana, Katakana, Katakana, Common, Common, Katakana, Katakana, Katakana,
/* U+3100-317f at offset 5632 */
Common, Common, Common, Common, Common, Bopomofo, Bopomofo, Bopomofo,
@@ -9281,7 +9286,7 @@ static const unsigned char uc_scripts[] = {
Hangul, Hangul, Hangul, Hangul, Hangul, Hangul, Hangul, Hangul,
Hangul, Hangul, Hangul, Hangul, Hangul, Hangul, Hangul, Hangul,
Hangul, Hangul, Hangul, Hangul, Hangul, Hangul, Hangul, Hangul,
- Hangul, Hangul, Hangul, Hangul, Hangul, Hangul, Hangul, Hangul,
+ Hangul, Hangul, Hangul, Hangul, Hangul, Hangul, Hangul, Hangul,
/* U+3180-31ff at offset 5760 */
Hangul, Hangul, Hangul, Hangul, Hangul, Hangul, Hangul, Hangul,
@@ -9299,7 +9304,7 @@ static const unsigned char uc_scripts[] = {
Common, Common, Common, Common, Common, Common, Common, Common,
Common, Common, Common, Common, Common, Common, Common, Common,
Katakana, Katakana, Katakana, Katakana, Katakana, Katakana, Katakana, Katakana,
- Katakana, Katakana, Katakana, Katakana, Katakana, Katakana, Katakana, Katakana,
+ Katakana, Katakana, Katakana, Katakana, Katakana, Katakana, Katakana, Katakana,
/* U+3200-327f at offset 5888 */
Hangul, Hangul, Hangul, Hangul, Hangul, Hangul, Hangul, Hangul,
@@ -9317,7 +9322,7 @@ static const unsigned char uc_scripts[] = {
Hangul, Hangul, Hangul, Hangul, Hangul, Hangul, Hangul, Hangul,
Hangul, Hangul, Hangul, Hangul, Hangul, Hangul, Hangul, Hangul,
Hangul, Hangul, Hangul, Hangul, Hangul, Hangul, Hangul, Hangul,
- Hangul, Hangul, Hangul, Hangul, Hangul, Hangul, Common, Common,
+ Hangul, Hangul, Hangul, Hangul, Hangul, Hangul, Common, Common,
/* U+d780-d7ff at offset 6016 */
Hangul, Hangul, Hangul, Hangul, Hangul, Hangul, Hangul, Hangul,
@@ -9335,7 +9340,7 @@ static const unsigned char uc_scripts[] = {
Common, Common, Common, Common, Common, Common, Common, Common,
Common, Common, Common, Common, Common, Common, Common, Common,
Common, Common, Common, Common, Common, Common, Common, Common,
- Common, Common, Common, Common, Common, Common, Common, Common,
+ Common, Common, Common, Common, Common, Common, Common, Common,
/* U+fb00-fb7f at offset 6144 */
Latin, Latin, Latin, Latin, Latin, Latin, Latin, Common,
@@ -9353,7 +9358,7 @@ static const unsigned char uc_scripts[] = {
Arabic, Arabic, Arabic, Arabic, Arabic, Arabic, Arabic, Arabic,
Arabic, Arabic, Arabic, Arabic, Arabic, Arabic, Arabic, Arabic,
Arabic, Arabic, Arabic, Arabic, Arabic, Arabic, Arabic, Arabic,
- Arabic, Arabic, Arabic, Arabic, Arabic, Arabic, Arabic, Arabic,
+ Arabic, Arabic, Arabic, Arabic, Arabic, Arabic, Arabic, Arabic,
/* U+fb80-fbff at offset 6272 */
Arabic, Arabic, Arabic, Arabic, Arabic, Arabic, Arabic, Arabic,
@@ -9371,7 +9376,7 @@ static const unsigned char uc_scripts[] = {
Arabic, Arabic, Arabic, Arabic, Arabic, Arabic, Arabic, Arabic,
Arabic, Arabic, Arabic, Arabic, Arabic, Arabic, Arabic, Arabic,
Arabic, Arabic, Arabic, Arabic, Arabic, Arabic, Arabic, Arabic,
- Arabic, Arabic, Arabic, Arabic, Arabic, Arabic, Arabic, Arabic,
+ Arabic, Arabic, Arabic, Arabic, Arabic, Arabic, Arabic, Arabic,
/* U+fd00-fd7f at offset 6400 */
Arabic, Arabic, Arabic, Arabic, Arabic, Arabic, Arabic, Arabic,
@@ -9389,7 +9394,7 @@ static const unsigned char uc_scripts[] = {
Arabic, Arabic, Arabic, Arabic, Arabic, Arabic, Arabic, Arabic,
Arabic, Arabic, Arabic, Arabic, Arabic, Arabic, Arabic, Arabic,
Arabic, Arabic, Arabic, Arabic, Arabic, Arabic, Arabic, Arabic,
- Arabic, Arabic, Arabic, Arabic, Arabic, Arabic, Arabic, Arabic,
+ Arabic, Arabic, Arabic, Arabic, Arabic, Arabic, Arabic, Arabic,
/* U+fd80-fdff at offset 6528 */
Arabic, Arabic, Arabic, Arabic, Arabic, Arabic, Arabic, Arabic,
@@ -9407,7 +9412,7 @@ static const unsigned char uc_scripts[] = {
Common, Common, Common, Common, Common, Common, Common, Common,
Common, Common, Common, Common, Common, Common, Common, Common,
Arabic, Arabic, Arabic, Arabic, Arabic, Arabic, Arabic, Arabic,
- Arabic, Arabic, Arabic, Arabic, Arabic, Common, Common, Common,
+ Arabic, Arabic, Arabic, Arabic, Arabic, Common, Common, Common,
/* U+fe00-fe7f at offset 6656 */
Inherited, Inherited, Inherited, Inherited, Inherited, Inherited, Inherited, Inherited,
@@ -9425,7 +9430,7 @@ static const unsigned char uc_scripts[] = {
Common, Common, Common, Common, Common, Common, Common, Common,
Common, Common, Common, Common, Common, Common, Common, Common,
Arabic, Arabic, Arabic, Arabic, Arabic, Common, Arabic, Arabic,
- Arabic, Arabic, Arabic, Arabic, Arabic, Arabic, Arabic, Arabic,
+ Arabic, Arabic, Arabic, Arabic, Arabic, Arabic, Arabic, Arabic,
/* U+fe80-feff at offset 6784 */
Arabic, Arabic, Arabic, Arabic, Arabic, Arabic, Arabic, Arabic,
@@ -9443,7 +9448,7 @@ static const unsigned char uc_scripts[] = {
Arabic, Arabic, Arabic, Arabic, Arabic, Arabic, Arabic, Arabic,
Arabic, Arabic, Arabic, Arabic, Arabic, Arabic, Arabic, Arabic,
Arabic, Arabic, Arabic, Arabic, Arabic, Arabic, Arabic, Arabic,
- Arabic, Arabic, Arabic, Arabic, Arabic, Common, Common, Common,
+ Arabic, Arabic, Arabic, Arabic, Arabic, Common, Common, Common,
/* U+ff80-ffff at offset 6912 */
Katakana, Katakana, Katakana, Katakana, Katakana, Katakana, Katakana, Katakana,
@@ -9461,9 +9466,21 @@ static const unsigned char uc_scripts[] = {
Common, Common, Common, Common, Common, Common, Common, Common,
Common, Common, Common, Common, Common, Common, Common, Common,
Common, Common, Common, Common, Common, Common, Common, Common,
- Common, Common, Common, Common, Common, Common, Common, Common
+ Common, Common, Common, Common, Common, Common, Common, Common
};
} // namespace QUnicodeTables
+Q_CORE_EXPORT int QT_FASTCALL QUnicodeTables::script(uint ucs4)
+{
+ if (ucs4 > 0xffff)
+ return Common;
+ int script = uc_scripts[ucs4 >> 7];
+ if (script < ScriptSentinel)
+ return script;
+ script = (((script - ScriptSentinel) * UnicodeBlockSize) + UnicodeBlockCount);
+ script = uc_scripts[script + (ucs4 & 0x7f)];
+ return script;
+}
+
QT_END_NAMESPACE
diff --git a/src/corelib/tools/qunicodetables_p.h b/src/corelib/tools/qunicodetables_p.h
index 5c7cc08..be52bf9 100644
--- a/src/corelib/tools/qunicodetables_p.h
+++ b/src/corelib/tools/qunicodetables_p.h
@@ -162,20 +162,6 @@ namespace QUnicodeTables {
enum { ScriptSentinel = 32 };
- // see http://www.unicode.org/reports/tr14/tr14-19.html
- // we don't use the XX, AI and CB properties and map them to AL instead.
- // as we don't support any EBDIC based OS'es, NL is ignored and mapped to AL as well.
- enum LineBreakClass {
- LineBreak_OP, LineBreak_CL, LineBreak_QU, LineBreak_GL, LineBreak_NS,
- LineBreak_EX, LineBreak_SY, LineBreak_IS, LineBreak_PR, LineBreak_PO,
- LineBreak_NU, LineBreak_AL, LineBreak_ID, LineBreak_IN, LineBreak_HY,
- LineBreak_BA, LineBreak_BB, LineBreak_B2, LineBreak_ZW, LineBreak_CM,
- LineBreak_WJ, LineBreak_H2, LineBreak_H3, LineBreak_JL, LineBreak_JV,
- LineBreak_JT, LineBreak_SA, LineBreak_SG,
- LineBreak_SP, LineBreak_CR, LineBreak_LF, LineBreak_BK
- };
-
-
enum GraphemeBreak {
GraphemeBreakOther,
GraphemeBreakCR,
@@ -217,6 +203,20 @@ namespace QUnicodeTables {
};
+ // see http://www.unicode.org/reports/tr14/tr14-19.html
+ // we don't use the XX, AI and CB properties and map them to AL instead.
+ // as we don't support any EBDIC based OS'es, NL is ignored and mapped to AL as well.
+ enum LineBreakClass {
+ LineBreak_OP, LineBreak_CL, LineBreak_QU, LineBreak_GL, LineBreak_NS,
+ LineBreak_EX, LineBreak_SY, LineBreak_IS, LineBreak_PR, LineBreak_PO,
+ LineBreak_NU, LineBreak_AL, LineBreak_ID, LineBreak_IN, LineBreak_HY,
+ LineBreak_BA, LineBreak_BB, LineBreak_B2, LineBreak_ZW, LineBreak_CM,
+ LineBreak_WJ, LineBreak_H2, LineBreak_H3, LineBreak_JL, LineBreak_JV,
+ LineBreak_JT, LineBreak_SA, LineBreak_SG,
+ LineBreak_SP, LineBreak_CR, LineBreak_LF, LineBreak_BK
+ };
+
+
Q_CORE_EXPORT QUnicodeTables::LineBreakClass QT_FASTCALL lineBreakClass(uint ucs4);
inline int lineBreakClass(const QChar &ch)
{ return lineBreakClass(ch.unicode()); }
diff --git a/src/corelib/tools/qvector.h b/src/corelib/tools/qvector.h
index 5613c12..c16aefb 100644
--- a/src/corelib/tools/qvector.h
+++ b/src/corelib/tools/qvector.h
@@ -53,6 +53,9 @@
#endif
#include <stdlib.h>
#include <string.h>
+#ifdef Q_COMPILER_INITIALIZER_LISTS
+#include <initializer_list>
+#endif
QT_BEGIN_HEADER
@@ -118,6 +121,13 @@ public:
inline QVector(const QVector<T> &v) : d(v.d) { d->ref.ref(); if (!d->sharable) detach_helper(); }
inline ~QVector() { if (!d) return; if (!d->ref.deref()) free(p); }
QVector<T> &operator=(const QVector<T> &v);
+#ifdef Q_COMPILER_RVALUE_REFS
+ inline QVector<T> operator=(QVector<T> &&other)
+ { qSwap(p, other.p); return *this; }
+#endif
+#ifdef Q_COMPILER_INITIALIZER_LISTS
+ inline QVector(std::initializer_list<T> args);
+#endif
bool operator==(const QVector<T> &v) const;
inline bool operator!=(const QVector<T> &v) const { return !(*this == v); }
@@ -293,11 +303,10 @@ public:
#ifndef QT_NO_STL
static inline QVector<T> fromStdVector(const std::vector<T> &vector)
- { QVector<T> tmp; qCopy(vector.begin(), vector.end(), std::back_inserter(tmp)); return tmp; }
+ { QVector<T> tmp; tmp.reserve(vector.size()); qCopy(vector.begin(), vector.end(), std::back_inserter(tmp)); return tmp; }
inline std::vector<T> toStdVector() const
- { std::vector<T> tmp; qCopy(constBegin(), constEnd(), std::back_inserter(tmp)); return tmp; }
+ { std::vector<T> tmp; tmp.reserve(size()); qCopy(constBegin(), constEnd(), std::back_inserter(tmp)); return tmp; }
#endif
-
private:
friend class QRegion; // Optimization for QRegion::rects()
@@ -377,10 +386,11 @@ inline void QVector<T>::replace(int i, const T &t)
template <typename T>
QVector<T> &QVector<T>::operator=(const QVector<T> &v)
{
- v.d->ref.ref();
+ QVectorData *o = v.d;
+ o->ref.ref();
if (!d->ref.deref())
free(p);
- d = v.d;
+ d = o;
if (!d->sharable)
detach_helper();
return *this;
@@ -425,6 +435,22 @@ QVector<T>::QVector(int asize, const T &t)
new (--i) T(t);
}
+#ifdef Q_COMPILER_INITIALIZER_LISTS
+template <typename T>
+QVector<T>::QVector(std::initializer_list<T> args)
+{
+ d = malloc(args.size());
+ d->ref = 1;
+ d->alloc = d->size = args.size();
+ d->sharable = true;
+ d->capacity = false;
+ T* i = p->array + d->size;
+ auto it = args.end();
+ while (i != p->array)
+ new (--i) T(*(--it));
+}
+#endif
+
template <typename T>
void QVector<T>::free(Data *x)
{