summaryrefslogtreecommitdiffstats
path: root/src/corelib
diff options
context:
space:
mode:
authorQt Forward Merge Bot <qt_forward_merge_bot@qt-project.org>2018-10-09 01:00:47 +0200
committerQt Forward Merge Bot <qt_forward_merge_bot@qt-project.org>2018-10-09 01:00:48 +0200
commit69b6845edbb43cf7000942d07f3a326383bdf6d2 (patch)
tree58755c33dfb18a51d194d0f774b1deca6135ce4a /src/corelib
parente2ab24d36f31395c2239b49ac26f2266b69444bd (diff)
parent8e5a2f63c3f6ee49d3f2e1985bf73de7769b0e72 (diff)
Merge remote-tracking branch 'origin/5.12' into dev
Diffstat (limited to 'src/corelib')
-rw-r--r--src/corelib/serialization/qcborarray.cpp26
-rw-r--r--src/corelib/serialization/qcborarray.h9
-rw-r--r--src/corelib/serialization/qcbormap.h16
-rw-r--r--src/corelib/serialization/qcborvalue.cpp17
-rw-r--r--src/corelib/serialization/qcborvalue_p.h1
-rw-r--r--src/corelib/tools/qdatetimeparser.cpp29
-rw-r--r--src/corelib/tools/qlist.h3
-rw-r--r--src/corelib/tools/qtimezoneprivate.cpp2
-rw-r--r--src/corelib/tools/qvarlengtharray.h3
-rw-r--r--src/corelib/tools/qvector.h3
10 files changed, 86 insertions, 23 deletions
diff --git a/src/corelib/serialization/qcborarray.cpp b/src/corelib/serialization/qcborarray.cpp
index c8df594c07..28ae40f3df 100644
--- a/src/corelib/serialization/qcborarray.cpp
+++ b/src/corelib/serialization/qcborarray.cpp
@@ -298,7 +298,8 @@ QCborValue QCborArray::at(qsizetype i) const
\fn QCborValueRef QCborArray::operator[](qsizetype i)
Returns a reference to the QCborValue element at position \a i in the
- array. The array must have at least \a i elements.
+ array. Indices beyond the end of the array will grow the array, filling
+ with undefined entries, until it has an entry at the specified index.
QCborValueRef has the exact same API as \l QCborValue, with one important
difference: if you assign new values to it, this map will be updated with
@@ -312,27 +313,34 @@ QCborValue QCborArray::at(qsizetype i) const
\fn void QCborArray::insert(qsizetype i, const QCborValue &value)
\fn void QCborArray::insert(qsizetype i, QCborValue &&value)
- Inserts \a value into the array at position \a i in this array. The array
- must have at least \a i elements before the insertion.
+ Inserts \a value into the array at position \a i in this array. If \a i is
+ -1, the entry is appended to the array. Pads the array with invalid entries
+ if \a i is greater than the prior size of the array.
\sa at(), operator[](), first(), last(), prepend(), append(),
removeAt(), takeAt(), extract()
*/
void QCborArray::insert(qsizetype i, const QCborValue &value)
{
- Q_ASSERT(size_t(i) <= size_t(size()) || i == -1);
- if (i < 0)
+ if (i < 0) {
+ Q_ASSERT(i == -1);
i = size();
- detach(qMax(i + 1, size()));
+ detach(i + 1);
+ } else {
+ d = QCborContainerPrivate::grow(d.data(), i); // detaches
+ }
d->insertAt(i, value);
}
void QCborArray::insert(qsizetype i, QCborValue &&value)
{
- Q_ASSERT(size_t(i) <= size_t(size()) || i == -1);
- if (i < 0)
+ if (i < 0) {
+ Q_ASSERT(i == -1);
i = size();
- detach(qMax(i + 1, size()));
+ detach(i + 1);
+ } else {
+ d = QCborContainerPrivate::grow(d.data(), i); // detaches
+ }
d->insertAt(i, value, QCborContainerPrivate::MoveContainer);
QCborContainerPrivate::resetValue(value);
}
diff --git a/src/corelib/serialization/qcborarray.h b/src/corelib/serialization/qcborarray.h
index 9663ee6acd..d96342cfa6 100644
--- a/src/corelib/serialization/qcborarray.h
+++ b/src/corelib/serialization/qcborarray.h
@@ -186,10 +186,15 @@ public:
QCborValue at(qsizetype i) const;
QCborValue first() const { return at(0); }
QCborValue last() const { return at(size() - 1); }
- QCborValue operator[](qsizetype i) const { return at(i); }
+ const QCborValue operator[](qsizetype i) const { return at(i); }
QCborValueRef first() { Q_ASSERT(!isEmpty()); return begin()[0]; }
QCborValueRef last() { Q_ASSERT(!isEmpty()); return begin()[size() - 1]; }
- QCborValueRef operator[](qsizetype i) { Q_ASSERT(i < size()); return begin()[i]; }
+ QCborValueRef operator[](qsizetype i)
+ {
+ if (i >= size())
+ insert(i, QCborValue());
+ return begin()[i];
+ }
void insert(qsizetype i, const QCborValue &value);
void insert(qsizetype i, QCborValue &&value);
diff --git a/src/corelib/serialization/qcbormap.h b/src/corelib/serialization/qcbormap.h
index 866b7cd743..0eb163a0a8 100644
--- a/src/corelib/serialization/qcbormap.h
+++ b/src/corelib/serialization/qcbormap.h
@@ -196,14 +196,22 @@ public:
{ const_iterator it = find(key); return it == end() ? QCborValue() : it.value(); }
QCborValue value(const QCborValue &key) const
{ const_iterator it = find(key); return it == end() ? QCborValue() : it.value(); }
- QCborValue operator[](qint64 key) const
+#if !defined(QT_NO_CAST_FROM_ASCII) && !defined(QT_RESTRICTED_CAST_FROM_ASCII)
+ template<size_t N> QT_ASCII_CAST_WARN const QCborValue value(const char (&key)[N]) const
+ { return value(QString::fromUtf8(key, N - 1)); }
+#endif
+ const QCborValue operator[](qint64 key) const
{ const_iterator it = find(key); return it == end() ? QCborValue() : it.value(); }
- QCborValue operator[](QLatin1String key) const
+ const QCborValue operator[](QLatin1String key) const
{ const_iterator it = find(key); return it == end() ? QCborValue() : it.value(); }
- QCborValue operator[](const QString & key) const
+ const QCborValue operator[](const QString & key) const
{ const_iterator it = find(key); return it == end() ? QCborValue() : it.value(); }
- QCborValue operator[](const QCborValue &key) const
+ const QCborValue operator[](const QCborValue &key) const
{ const_iterator it = find(key); return it == end() ? QCborValue() : it.value(); }
+#if !defined(QT_NO_CAST_FROM_ASCII) && !defined(QT_RESTRICTED_CAST_FROM_ASCII)
+ template<size_t N> QT_ASCII_CAST_WARN const QCborValue operator[](const char (&key)[N]) const
+ { return operator[](QString::fromUtf8(key, N - 1)); }
+#endif
QCborValueRef operator[](qint64 key);
QCborValueRef operator[](QLatin1String key);
QCborValueRef operator[](const QString & key);
diff --git a/src/corelib/serialization/qcborvalue.cpp b/src/corelib/serialization/qcborvalue.cpp
index 8673628c69..935f761585 100644
--- a/src/corelib/serialization/qcborvalue.cpp
+++ b/src/corelib/serialization/qcborvalue.cpp
@@ -859,6 +859,23 @@ QCborContainerPrivate *QCborContainerPrivate::detach(QCborContainerPrivate *d, q
return d;
}
+/*!
+ Prepare for an insertion at position \a index
+
+ Detaches and ensures there are at least index entries in the array, padding
+ with Undefined as needed.
+*/
+QCborContainerPrivate *QCborContainerPrivate::grow(QCborContainerPrivate *d, qsizetype index)
+{
+ Q_ASSERT(index >= 0);
+ d = detach(d, index + 1);
+ Q_ASSERT(d);
+ int j = d->elements.size();
+ while (j < index)
+ d->append(Undefined());
+ return d;
+}
+
// Copies or moves \a value into element at position \a e. If \a disp is
// CopyContainer, then this function increases the reference count of the
// container, but otherwise leaves it unmodified. If \a disp is MoveContainer,
diff --git a/src/corelib/serialization/qcborvalue_p.h b/src/corelib/serialization/qcborvalue_p.h
index 3a28707056..4050d18fa9 100644
--- a/src/corelib/serialization/qcborvalue_p.h
+++ b/src/corelib/serialization/qcborvalue_p.h
@@ -136,6 +136,7 @@ public:
void compact(qsizetype reserved);
static QCborContainerPrivate *clone(QCborContainerPrivate *d, qsizetype reserved = -1);
static QCborContainerPrivate *detach(QCborContainerPrivate *d, qsizetype reserved);
+ static QCborContainerPrivate *grow(QCborContainerPrivate *d, qsizetype index);
qptrdiff addByteData(const char *block, qsizetype len)
{
diff --git a/src/corelib/tools/qdatetimeparser.cpp b/src/corelib/tools/qdatetimeparser.cpp
index 18c44c3a17..e6afd510fd 100644
--- a/src/corelib/tools/qdatetimeparser.cpp
+++ b/src/corelib/tools/qdatetimeparser.cpp
@@ -1341,12 +1341,33 @@ QDateTimeParser::scanString(const QDateTime &defaultValue,
const QDate date(year, month, day);
const QTime time(hour, minute, second, msec);
- return StateNode(
+ const QDateTime when =
#if QT_CONFIG(timezone)
- tspec == Qt::TimeZone ? QDateTime(date, time, timeZone) :
+ tspec == Qt::TimeZone ? QDateTime(date, time, timeZone) :
#endif
- QDateTime(date, time, tspec, zoneOffset),
- state, padding, conflicts);
+ QDateTime(date, time, tspec, zoneOffset);
+
+ // If hour wasn't specified, check the default we're using exists on the
+ // given date (which might be a spring-forward, skipping an hour).
+ if (parserType == QVariant::DateTime && !(isSet & HourSectionMask) && !when.isValid()) {
+ qint64 msecs = when.toMSecsSinceEpoch();
+ // Fortunately, that gets a useful answer ...
+ const QDateTime replace =
+#if QT_CONFIG(timezone)
+ tspec == Qt::TimeZone
+ ? QDateTime::fromMSecsSinceEpoch(msecs, timeZone) :
+#endif
+ QDateTime::fromMSecsSinceEpoch(msecs, tspec, zoneOffset);
+ const QTime tick = replace.time();
+ if (replace.date() == date
+ && (!(isSet & MinuteSection) || tick.minute() == minute)
+ && (!(isSet & SecondSection) || tick.second() == second)
+ && (!(isSet & MSecSection) || tick.msec() == msec)) {
+ return StateNode(replace, state, padding, conflicts);
+ }
+ }
+
+ return StateNode(when, state, padding, conflicts);
}
/*!
diff --git a/src/corelib/tools/qlist.h b/src/corelib/tools/qlist.h
index c00220ad3a..49ccbc9c9f 100644
--- a/src/corelib/tools/qlist.h
+++ b/src/corelib/tools/qlist.h
@@ -413,7 +413,8 @@ private:
bool isValidIterator(const iterator &i) const Q_DECL_NOTHROW
{
- return (constBegin().i <= i.i) && (i.i <= constEnd().i);
+ const std::less<const Node *> less = {};
+ return !less(i.i, cbegin().i) && !less(cend().i, i.i);
}
private:
diff --git a/src/corelib/tools/qtimezoneprivate.cpp b/src/corelib/tools/qtimezoneprivate.cpp
index 8bf7336a42..569b343187 100644
--- a/src/corelib/tools/qtimezoneprivate.cpp
+++ b/src/corelib/tools/qtimezoneprivate.cpp
@@ -440,7 +440,7 @@ QTimeZonePrivate::Data QTimeZonePrivate::dataForLocalTime(qint64 forLocalMSecs,
utcEpochMSecs = forStd;
} else {
// Invalid forLocalMSecs: in spring-forward gap.
- const int dstStep = daylightTimeOffset(early < late ? imminent : recent);
+ const int dstStep = daylightTimeOffset(early < late ? imminent : recent) * 1000;
Q_ASSERT(dstStep); // There can't be a transition without it !
utcEpochMSecs = (hint > 0) ? forStd - dstStep : forDst + dstStep;
}
diff --git a/src/corelib/tools/qvarlengtharray.h b/src/corelib/tools/qvarlengtharray.h
index b74b1fd123..597e7464cb 100644
--- a/src/corelib/tools/qvarlengtharray.h
+++ b/src/corelib/tools/qvarlengtharray.h
@@ -254,7 +254,8 @@ private:
bool isValidIterator(const const_iterator &i) const
{
- return (i <= constEnd()) && (constBegin() <= i);
+ const std::less<const T*> less = {};
+ return !less(cend(), i) && !less(i, cbegin());
}
};
diff --git a/src/corelib/tools/qvector.h b/src/corelib/tools/qvector.h
index 345ba4b097..30fd7b2865 100644
--- a/src/corelib/tools/qvector.h
+++ b/src/corelib/tools/qvector.h
@@ -306,7 +306,8 @@ private:
void destruct(T *from, T *to);
bool isValidIterator(const iterator &i) const
{
- return (i <= d->end()) && (d->begin() <= i);
+ const std::less<const T*> less = {};
+ return !less(d->end(), i) && !less(i, d->begin());
}
class AlignmentDummy { Data header; T array[1]; };
};