diff options
author | Edward Welbourne <edward.welbourne@qt.io> | 2016-07-19 19:51:41 +0200 |
---|---|---|
committer | Edward Welbourne <edward.welbourne@qt.io> | 2016-07-19 20:14:40 +0200 |
commit | 782ebeada125e3d8a293c7806e34cc737c30ddda (patch) | |
tree | 5516ad24a7532d650289758abd5e92a35bc2240e /src/corelib/tools | |
parent | 091df96fb8da356dc9de81dc390f55e66d4d7c01 (diff) | |
parent | 62cbb434579a56871f0917bc306d592055381c00 (diff) |
Merge remote-tracking branch 'origin/5.7' into dev
Conflicts:
qmake/library/qmakebuiltins.cpp
qmake/library/qmakeevaluator.cpp
qmake/library/qmakeevaluator.h
qmake/project.h
QMakeEvaluator:
* evaluateConditional(): one side changed return type, the other
changed a parameter type.
* split_value_list(): one side changed a parameter adjacent to where ...
* expandVariableReferences(): ... the other killed one overload and
changed the survivor
src/corelib/io/qlockfile_unix.cpp
One side changed a #if condition, the other moved NETBSD's part of
what it controlled.
src/corelib/tools/qdatetime.cpp
One side fixed a reachable Q_UNREACHABLE in toMSecsSinceEpoch(), the
other moved it from the private class to the public one, in the midst
of the "short date-time" optimization, which confused diff entirely.
One side changed a QStringLiteral to QLatin1String, the other rewrote
adjoining code.
src/network/kernel/qauthenticator.cpp
Both rewrote a line, equivalently; kept the dev version.
src/platformsupport/fontdatabases/mac/qfontengine_coretext.mm
src/platformsupport/fontdatabases/mac/qfontengine_coretext_p.h
One side changed #if-ery that the other removed.
tools/configure/configureapp.cpp
One side added a check to -target parsing; the other killed -target.
tests/auto/testlib/selftests/expected_cmptest.lightxml
tests/auto/testlib/selftests/expected_cmptest.teamcity
tests/auto/testlib/selftests/expected_cmptest.txt
tests/auto/testlib/selftests/expected_cmptest.xml
tests/auto/testlib/selftests/expected_cmptest.xunitxml
Regenerated using generate_expected_output.py
I note that quite a few other expected_* come out changed, now.
There was no git-conflict in
src/widgets/kernel/qformlayout.cpp
but it didn't compile; one side removed some unused methods; the other
found uses for one of them. Put FixedColumnMatrix<>::removeRow(int)
back for its new user.
Change-Id: I8cc2a71add48c0a848e13cfc47b5a7754e8ca584
Diffstat (limited to 'src/corelib/tools')
-rw-r--r-- | src/corelib/tools/qdatetime.cpp | 18 | ||||
-rw-r--r-- | src/corelib/tools/qstring.cpp | 111 | ||||
-rw-r--r-- | src/corelib/tools/qstring.h | 4 | ||||
-rw-r--r-- | src/corelib/tools/qstringbuilder.h | 2 | ||||
-rw-r--r-- | src/corelib/tools/qtimezoneprivate_icu.cpp | 2 | ||||
-rw-r--r-- | src/corelib/tools/qtimezoneprivate_mac.mm | 3 |
6 files changed, 93 insertions, 47 deletions
diff --git a/src/corelib/tools/qdatetime.cpp b/src/corelib/tools/qdatetime.cpp index d6b90efb33..ee5ee5c362 100644 --- a/src/corelib/tools/qdatetime.cpp +++ b/src/corelib/tools/qdatetime.cpp @@ -3513,7 +3513,7 @@ qint64 QDateTime::toMSecsSinceEpoch() const case Qt::TimeZone: #ifdef QT_BOOTSTRAPPED - break; + return 0; #else return QDateTimePrivate::zoneMSecsToEpochMSecs(d->m_msecs, d->m_timeZone); #endif @@ -3771,7 +3771,7 @@ QString QDateTime::toString(Qt::DateFormat format) const .arg(tm.toString(Qt::TextDate)) .arg(dt.year()); if (timeSpec() != Qt::LocalTime) { - buf += QStringLiteral(" GMT"); + buf += QLatin1String(" GMT"); if (getSpec(d) == Qt::OffsetFromUTC) buf += toOffsetString(Qt::TextDate, offsetFromUtc()); } @@ -5019,7 +5019,12 @@ QDataStream &operator>>(QDataStream &in, QDate &date) QDataStream &operator<<(QDataStream &out, const QTime &time) { - return out << quint32(time.mds); + if (out.version() >= QDataStream::Qt_4_0) { + return out << quint32(time.mds); + } else { + // Qt3 had no support for reading -1, QTime() was valid and serialized as 0 + return out << quint32(time.isNull() ? 0 : time.mds); + } } /*! @@ -5034,7 +5039,12 @@ QDataStream &operator>>(QDataStream &in, QTime &time) { quint32 ds; in >> ds; - time.mds = int(ds); + if (in.version() >= QDataStream::Qt_4_0) { + time.mds = int(ds); + } else { + // Qt3 would write 0 for a null time + time.mds = (ds == 0) ? QTime::NullTime : int(ds); + } return in; } diff --git a/src/corelib/tools/qstring.cpp b/src/corelib/tools/qstring.cpp index 32f12bd092..a8e924b62d 100644 --- a/src/corelib/tools/qstring.cpp +++ b/src/corelib/tools/qstring.cpp @@ -1786,17 +1786,12 @@ void QString::reallocData(uint alloc, bool grow) } } +#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) void QString::expand(int i) { - int sz = d->size; - resize(qMax(i + 1, sz)); - if (d->size - 1 > sz) { - ushort *n = d->data() + d->size - 1; - ushort *e = d->data() + sz; - while (n != e) - * --n = ' '; - } + resize(qMax(i + 1, d->size), QLatin1Char(' ')); } +#endif /*! \fn void QString::clear() @@ -1982,7 +1977,10 @@ QString &QString::insert(int i, QLatin1String str) return *this; int len = str.size(); - expand(qMax(d->size, i) + len - 1); + if (Q_UNLIKELY(i > d->size)) + resize(i + len, QLatin1Char(' ')); + else + resize(d->size + len); ::memmove(d->data() + i + len, d->data() + i, (d->size - i - len) * sizeof(QChar)); qt_from_latin1(d->data() + i, s, uint(len)); @@ -2012,7 +2010,10 @@ QString& QString::insert(int i, const QChar *unicode, int size) return *this; } - expand(qMax(d->size, i) + size - 1); + if (Q_UNLIKELY(i > d->size)) + resize(i + size, QLatin1Char(' ')); + else + resize(d->size + size); ::memmove(d->data() + i + size, d->data() + i, (d->size - i - size) * sizeof(QChar)); memcpy(d->data() + i, s, size * sizeof(QChar)); @@ -2032,7 +2033,10 @@ QString& QString::insert(int i, QChar ch) i += d->size; if (i < 0) return *this; - expand(qMax(i, d->size)); + if (Q_UNLIKELY(i > d->size)) + resize(i + 1, QLatin1Char(' ')); + else + resize(d->size + 1); ::memmove(d->data() + i + 1, d->data() + i, (d->size - i - 1) * sizeof(QChar)); d->data()[i] = ch.unicode(); return *this; @@ -2404,26 +2408,40 @@ QString &QString::replace(const QString &before, const QString &after, Qt::CaseS return replace(before.constData(), before.size(), after.constData(), after.size(), cs); } +namespace { // helpers for replace and its helper: +QChar *textCopy(const QChar *start, int len) +{ + const size_t size = len * sizeof(QChar); + QChar *const copy = static_cast<QChar *>(::malloc(size)); + Q_CHECK_PTR(copy); + ::memcpy(copy, start, size); + return copy; +} + +bool pointsIntoRange(const QChar *ptr, const ushort *base, int len) +{ + const QChar *const start = reinterpret_cast<const QChar *>(base); + return start <= ptr && ptr < start + len; +} +} // end namespace + /*! \internal */ void QString::replace_helper(uint *indices, int nIndices, int blen, const QChar *after, int alen) { - // copy *after in case it lies inside our own d->data() area - // (which we could possibly invalidate via a realloc or corrupt via memcpy operations.) - QChar *afterBuffer = const_cast<QChar *>(after); - if (after >= reinterpret_cast<QChar *>(d->data()) && after < reinterpret_cast<QChar *>(d->data()) + d->size) { - afterBuffer = static_cast<QChar *>(::malloc(alen*sizeof(QChar))); - Q_CHECK_PTR(afterBuffer); - ::memcpy(afterBuffer, after, alen*sizeof(QChar)); - } + // Copy after if it lies inside our own d->data() area (which we could + // possibly invalidate via a realloc or modify by replacement). + QChar *afterBuffer = 0; + if (pointsIntoRange(after, d->data(), d->size)) // Use copy in place of vulnerable original: + after = afterBuffer = textCopy(after, alen); QT_TRY { if (blen == alen) { // replace in place detach(); for (int i = 0; i < nIndices; ++i) - memcpy(d->data() + indices[i], afterBuffer, alen * sizeof(QChar)); + memcpy(d->data() + indices[i], after, alen * sizeof(QChar)); } else if (alen < blen) { // replace from front detach(); @@ -2439,7 +2457,7 @@ void QString::replace_helper(uint *indices, int nIndices, int blen, const QChar to += msize; } if (alen) { - memcpy(d->data() + to, afterBuffer, alen*sizeof(QChar)); + memcpy(d->data() + to, after, alen * sizeof(QChar)); to += alen; } movestart = indices[i] + blen; @@ -2462,17 +2480,15 @@ void QString::replace_helper(uint *indices, int nIndices, int blen, const QChar int moveto = insertstart + alen; memmove(d->data() + moveto, d->data() + movestart, (moveend - movestart)*sizeof(QChar)); - memcpy(d->data() + insertstart, afterBuffer, alen*sizeof(QChar)); + memcpy(d->data() + insertstart, after, alen * sizeof(QChar)); moveend = movestart-blen; } } } QT_CATCH(const std::bad_alloc &) { - if (afterBuffer != after) - ::free(afterBuffer); + ::free(afterBuffer); QT_RETHROW; } - if (afterBuffer != after) - ::free(afterBuffer); + ::free(afterBuffer); } /*! @@ -2501,31 +2517,48 @@ QString &QString::replace(const QChar *before, int blen, return *this; QStringMatcher matcher(before, blen, cs); + QChar *beforeBuffer = 0, *afterBuffer = 0; int index = 0; while (1) { uint indices[1024]; uint pos = 0; - while (pos < 1023) { + while (pos < 1024) { index = matcher.indexIn(*this, index); if (index == -1) break; indices[pos++] = index; - index += blen; - // avoid infinite loop - if (!blen) + if (blen) // Step over before: + index += blen; + else // Only count one instance of empty between any two characters: index++; } - if (!pos) + if (!pos) // Nothing to replace break; + if (Q_UNLIKELY(index != -1)) { + /* + We're about to change data, that before and after might point + into, and we'll need that data for our next batch of indices. + */ + if (!afterBuffer && pointsIntoRange(after, d->data(), d->size)) + after = afterBuffer = textCopy(after, alen); + + if (!beforeBuffer && pointsIntoRange(before, d->data(), d->size)) { + beforeBuffer = textCopy(before, blen); + matcher = QStringMatcher(beforeBuffer, blen, cs); + } + } + replace_helper(indices, pos, blen, after, alen); - if (index == -1) + if (Q_LIKELY(index == -1)) // Nothing left to replace break; - // index has to be adjusted in case we get back into the loop above. + // The call to replace_helper just moved what index points at: index += pos*(alen-blen); } + ::free(afterBuffer); + ::free(beforeBuffer); return *this; } @@ -2556,26 +2589,26 @@ QString& QString::replace(QChar ch, const QString &after, Qt::CaseSensitivity cs uint indices[1024]; uint pos = 0; if (cs == Qt::CaseSensitive) { - while (pos < 1023 && index < d->size) { + while (pos < 1024 && index < d->size) { if (d->data()[index] == cc) indices[pos++] = index; index++; } } else { - while (pos < 1023 && index < d->size) { + while (pos < 1024 && index < d->size) { if (QChar::toCaseFolded(d->data()[index]) == cc) indices[pos++] = index; index++; } } - if (!pos) + if (!pos) // Nothing to replace break; replace_helper(indices, pos, 1, after.constData(), after.d->size); - if (index == -1) + if (Q_LIKELY(index == -1)) // Nothing left to replace break; - // index has to be adjusted in case we get back into the loop above. + // The call to replace_helper just moved what index points at: index += pos*(after.d->size - 1); } return *this; @@ -5001,7 +5034,7 @@ void QString::truncate(int pos) 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. + empty string; if \a n is negative, it is equivalent to passing zero. Example: \snippet qstring/main.cpp 15 diff --git a/src/corelib/tools/qstring.h b/src/corelib/tools/qstring.h index ec959b50a0..a110c129de 100644 --- a/src/corelib/tools/qstring.h +++ b/src/corelib/tools/qstring.h @@ -821,7 +821,9 @@ private: 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); +#endif QString multiArg(int numArgs, const QString **args) const; static int compare_helper(const QChar *data1, int length1, const QChar *data2, int length2, @@ -1008,7 +1010,7 @@ public: inline operator QChar() const { return i < s.d->size ? s.d->data()[i] : 0; } inline QCharRef &operator=(QChar c) - { if (i >= s.d->size) s.expand(i); else s.detach(); + { if (i >= s.d->size) s.resize(i + 1, QLatin1Char(' ')); else s.detach(); s.d->data()[i] = c.unicode(); return *this; } // An operator= for each QChar cast constructors diff --git a/src/corelib/tools/qstringbuilder.h b/src/corelib/tools/qstringbuilder.h index 8ce98cbd71..b2832b5fbe 100644 --- a/src/corelib/tools/qstringbuilder.h +++ b/src/corelib/tools/qstringbuilder.h @@ -82,7 +82,7 @@ struct QStringBuilderCommon T toLower() const { return resolved().toLower(); } protected: - const T resolved() const { return *static_cast<const Builder*>(this); } + T resolved() const { return *static_cast<const Builder*>(this); } }; template<typename Builder, typename T> diff --git a/src/corelib/tools/qtimezoneprivate_icu.cpp b/src/corelib/tools/qtimezoneprivate_icu.cpp index a7036808db..c088fe7694 100644 --- a/src/corelib/tools/qtimezoneprivate_icu.cpp +++ b/src/corelib/tools/qtimezoneprivate_icu.cpp @@ -332,7 +332,7 @@ QString QIcuTimeZonePrivate::displayName(QTimeZone::TimeType timeType, { // Return standard offset format name as ICU C api doesn't support it yet if (nameType == QTimeZone::OffsetName) { - const Data nowData = data(QDateTime::currentDateTimeUtc().toMSecsSinceEpoch()); + const Data nowData = data(QDateTime::currentMSecsSinceEpoch()); // We can't use transitions reliably to find out right dst offset // Instead use dst offset api to try get it if needed if (timeType == QTimeZone::DaylightTime) diff --git a/src/corelib/tools/qtimezoneprivate_mac.mm b/src/corelib/tools/qtimezoneprivate_mac.mm index 3a665c2b00..77c04ac20c 100644 --- a/src/corelib/tools/qtimezoneprivate_mac.mm +++ b/src/corelib/tools/qtimezoneprivate_mac.mm @@ -59,6 +59,7 @@ QT_BEGIN_NAMESPACE // Create the system default time zone QMacTimeZonePrivate::QMacTimeZonePrivate() + : m_nstz(0) { init(systemTimeZoneId()); } @@ -106,7 +107,7 @@ QString QMacTimeZonePrivate::displayName(QTimeZone::TimeType timeType, { // TODO Mac doesn't support OffsetName yet so use standard offset name if (nameType == QTimeZone::OffsetName) { - const Data nowData = data(QDateTime::currentDateTimeUtc().toMSecsSinceEpoch()); + const Data nowData = data(QDateTime::currentMSecsSinceEpoch()); // TODO Cheat for now, assume if has dst the offset if 1 hour if (timeType == QTimeZone::DaylightTime && hasDaylightTime()) return isoOffsetFormat(nowData.standardTimeOffset + 3600); |