From 96810e3863272eb5463ba5c07d82544810bdb3f8 Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Thu, 12 Aug 2021 14:02:37 +0200 Subject: [PATCH] QDateTime: port to QStringTokenizer and QVLA MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The code isn't easily linearized to work directly with QStringTokenizer, which is a forward-only range, but we can at least remove the (non-error) memory allocations by supplying a suitably-sized QVLA to tokenize into instead of the default QList. Change-Id: I1aa11a5fbbe66ede4ec2e5b2090044a39052a241 Reviewed-by: Mårten Nordheim Reviewed-by: Qt CI Bot Reviewed-by: Thiago Macieira Reviewed-by: Edward Welbourne --- src/corelib/time/qdatetime.cpp | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/corelib/time/qdatetime.cpp b/src/corelib/time/qdatetime.cpp index 9ddd207662..aa14f4525e 100644 --- a/src/corelib/time/qdatetime.cpp +++ b/src/corelib/time/qdatetime.cpp @@ -153,7 +153,8 @@ static ParsedRfcDateTime rfcDateImpl(QStringView s) // or "ddd MMM dd[ hh:mm:ss] yyyy [±hhmm]" - permissive RFC 850, 1036 (read only) ParsedRfcDateTime result; - auto words = QStringView{s}.split(u' ', Qt::SkipEmptyParts); + QVarLengthArray words; + s.tokenize(u' ', Qt::SkipEmptyParts).toContainer(words); if (words.size() < 3 || words.size() > 6) return result; const QChar colon(u':'); @@ -1483,7 +1484,8 @@ QDate QDate::fromString(QStringView string, Qt::DateFormat format) default: case Qt::TextDate: { // Documented as "ddd MMM d yyyy" - auto parts = string.split(u' ', Qt::SkipEmptyParts); + QVarLengthArray parts; + string.tokenize(u' ', Qt::SkipEmptyParts).toContainer(parts); if (parts.count() != 4) return QDate(); @@ -5119,7 +5121,8 @@ QDateTime QDateTime::fromString(QStringView string, Qt::DateFormat format) return QDateTime(date, time, spec, offset); } case Qt::TextDate: { - QList parts = string.split(u' ', Qt::SkipEmptyParts); + QVarLengthArray parts; + string.tokenize(u' ', Qt::SkipEmptyParts).toContainer(parts); // Documented as "ddd MMM d HH:mm:ss yyyy" with optional offset-suffix; // and allow time either before or after year.