From b33ccd99e130c02d582ae42158663e13f093b7c3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?M=C3=A5rten=20Nordheim?= Date: Wed, 25 Aug 2021 16:18:04 +0200 Subject: [PATCH] QNetworkCookie: Clean up Rewrite the regex to not capture the things we ignore anyway. Use capturedView to avoid allocating a string just to turn it into an int. Fix a (usually) ifdef-ed out piece of code that was still calling a QRegExp function. Make the QRegularExpression static const to save it from having to recompile every time. Change-Id: I2f4841a2bc35df4e6cea44aec72432410583f770 Reviewed-by: Edward Welbourne --- src/network/access/qnetworkcookie.cpp | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/network/access/qnetworkcookie.cpp b/src/network/access/qnetworkcookie.cpp index 8dbb36829da..81e321d86ae 100644 --- a/src/network/access/qnetworkcookie.cpp +++ b/src/network/access/qnetworkcookie.cpp @@ -664,7 +664,8 @@ static QDateTime parseDateString(const QByteArray &dateString) int zoneOffset = -1; // hour:minute:second.ms pm - QRegularExpression timeRx(QLatin1String("(\\d{1,2}):(\\d{1,2})(:(\\d{1,2})|)(\\.(\\d{1,3})|)((\\s{0,}(am|pm))|)")); + static const QRegularExpression timeRx( + u"(\\d\\d?):(\\d\\d?)(?::(\\d\\d?)(?:\\.(\\d{1,3}))?)?(?:\\s*(am|pm))?"_qs); int at = 0; while (at < dateString.length()) { @@ -748,18 +749,17 @@ static QDateTime parseDateString(const QByteArray &dateString) // or else we get use-after-free issues: QString dateToString = QString::fromLatin1(dateString); if (auto match = timeRx.match(dateToString, at); match.hasMatch()) { - QStringList list = match.capturedTexts(); - int h = match.captured(1).toInt(); - int m = match.captured(2).toInt(); - int s = match.captured(4).toInt(); - int ms = match.captured(6).toInt(); - QString ampm = match.captured(9); + int h = match.capturedView(1).toInt(); + int m = match.capturedView(2).toInt(); + int s = match.capturedView(3).toInt(); + int ms = match.capturedView(4).toInt(); + QStringView ampm = match.capturedView(5); if (h < 12 && !ampm.isEmpty()) if (ampm == QLatin1String("pm")) h += 12; time = QTime(h, m, s, ms); #ifdef PARSEDATESTRINGDEBUG - qDebug() << "Time:" << list << timeRx.matchedLength(); + qDebug() << "Time:" << match.capturedTexts() << match.capturedLength(); #endif at += match.capturedLength(); continue;