summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarc Mutz <marc.mutz@kdab.com>2015-01-21 00:51:34 +0100
committerMarc Mutz <marc.mutz@kdab.com>2015-02-17 15:03:18 +0000
commitd8d114989ab653cf77304cafc65392d295212c00 (patch)
tree423f1c2d71dd959c4e1189f664acc251619cc3cf
parent62475eb8b09ab1d26ba02032e110bb44872392a6 (diff)
QDateTime: optimize rfcDateImpl()
Get the captured texts once and use indexing into the QStringList instead of repeatedly calling QRegExp::cap(n). (Impressive) effects on Linux GCC 4.9 stripped release builds: text -2876B data +-0B relocs +-0 Change-Id: I3a02eab1a691f31c30654cd89a0c030414b40de0 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
-rw-r--r--src/corelib/tools/qdatetime.cpp42
1 files changed, 22 insertions, 20 deletions
diff --git a/src/corelib/tools/qdatetime.cpp b/src/corelib/tools/qdatetime.cpp
index a25e913d92..a31e91db97 100644
--- a/src/corelib/tools/qdatetime.cpp
+++ b/src/corelib/tools/qdatetime.cpp
@@ -202,20 +202,21 @@ static void rfcDateImpl(const QString &s, QDate *dd = 0, QTime *dt = 0, int *utc
// Matches "Wdy, DD Mon YYYY HH:mm:ss ±hhmm" (Wdy, being optional)
QRegExp rex(QStringLiteral("^(?:[A-Z][a-z]+,)?[ \\t]*(\\d{1,2})[ \\t]+([A-Z][a-z]+)[ \\t]+(\\d\\d\\d\\d)(?:[ \\t]+(\\d\\d):(\\d\\d)(?::(\\d\\d))?)?[ \\t]*(?:([+-])(\\d\\d)(\\d\\d))?"));
if (s.indexOf(rex) == 0) {
+ const QStringList cap = rex.capturedTexts();
if (dd) {
- day = rex.cap(1).toInt();
- month = qt_monthNumberFromShortName(rex.cap(2));
- year = rex.cap(3).toInt();
+ day = cap[1].toInt();
+ month = qt_monthNumberFromShortName(cap[2]);
+ year = cap[3].toInt();
}
if (dt) {
- if (!rex.cap(4).isEmpty()) {
- hour = rex.cap(4).toInt();
- min = rex.cap(5).toInt();
- sec = rex.cap(6).toInt();
+ if (!cap[4].isEmpty()) {
+ hour = cap[4].toInt();
+ min = cap[5].toInt();
+ sec = cap[6].toInt();
}
- positiveOffset = (rex.cap(7) == QLatin1String("+"));
- hourOffset = rex.cap(8).toInt();
- minOffset = rex.cap(9).toInt();
+ positiveOffset = (cap[7] == QLatin1String("+"));
+ hourOffset = cap[8].toInt();
+ minOffset = cap[9].toInt();
}
if (utcOffset)
*utcOffset = ((hourOffset * 60 + minOffset) * (positiveOffset ? 60 : -60));
@@ -223,20 +224,21 @@ static void rfcDateImpl(const QString &s, QDate *dd = 0, QTime *dt = 0, int *utc
// Matches "Wdy Mon DD HH:mm:ss YYYY"
QRegExp rex(QStringLiteral("^[A-Z][a-z]+[ \\t]+([A-Z][a-z]+)[ \\t]+(\\d\\d)(?:[ \\t]+(\\d\\d):(\\d\\d):(\\d\\d))?[ \\t]+(\\d\\d\\d\\d)[ \\t]*(?:([+-])(\\d\\d)(\\d\\d))?"));
if (s.indexOf(rex) == 0) {
+ const QStringList cap = rex.capturedTexts();
if (dd) {
- month = qt_monthNumberFromShortName(rex.cap(1));
- day = rex.cap(2).toInt();
- year = rex.cap(6).toInt();
+ month = qt_monthNumberFromShortName(cap[1]);
+ day = cap[2].toInt();
+ year = cap[6].toInt();
}
if (dt) {
- if (!rex.cap(3).isEmpty()) {
- hour = rex.cap(3).toInt();
- min = rex.cap(4).toInt();
- sec = rex.cap(5).toInt();
+ if (!cap[3].isEmpty()) {
+ hour = cap[3].toInt();
+ min = cap[4].toInt();
+ sec = cap[5].toInt();
}
- positiveOffset = (rex.cap(7) == QLatin1String("+"));
- hourOffset = rex.cap(8).toInt();
- minOffset = rex.cap(9).toInt();
+ positiveOffset = (cap[7] == QLatin1String("+"));
+ hourOffset = cap[8].toInt();
+ minOffset = cap[9].toInt();
}
if (utcOffset)
*utcOffset = ((hourOffset * 60 + minOffset) * (positiveOffset ? 60 : -60));