summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMårten Nordheim <marten.nordheim@qt.io>2020-12-01 17:36:15 +0100
committerMårten Nordheim <marten.nordheim@qt.io>2021-02-11 15:38:17 +0100
commit6e89ed5a3c13c15b4e62eda7cf46acd8793e84f8 (patch)
treec63ef434c0e5ac161ccc12ba2029f9b948675938
parent6ec3321875b9fb2f72cc875ba191aa8123e7d5a5 (diff)
Add a shortcut in QDateTimeParser::findTimeZone for UTC
In a small example program using HTTPS (on Windows with Schannel) >40% of the time was spent initializing the backend, attempting to find the time zone used in various certificates. By adding an early check to see if the requested time zone is UTC (or an alias ('Z')) we can skip most of the lookup that was required. In the example program this cut away ~200ms of a total of ~550ms. Change-Id: I4d29568653e02b64feebbf329469899eb7be1494 Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
-rw-r--r--src/corelib/time/qdatetimeparser.cpp9
1 files changed, 8 insertions, 1 deletions
diff --git a/src/corelib/time/qdatetimeparser.cpp b/src/corelib/time/qdatetimeparser.cpp
index c64f622a57..b17135ef36 100644
--- a/src/corelib/time/qdatetimeparser.cpp
+++ b/src/corelib/time/qdatetimeparser.cpp
@@ -1657,8 +1657,11 @@ QDateTimeParser::ParsedSection QDateTimeParser::findUtcOffset(QStringView str) c
{
const bool startsWithUtc = str.startsWith(QLatin1String("UTC"));
// Get rid of UTC prefix if it exists
- if (startsWithUtc)
+ if (startsWithUtc) {
str = str.sliced(3);
+ if (str.isEmpty())
+ return ParsedSection(Acceptable, 0, 3);
+ }
const bool negativeSign = str.startsWith(QLatin1Char('-'));
// Must start with a sign:
@@ -1759,6 +1762,10 @@ QDateTimeParser::ParsedSection
QDateTimeParser::findTimeZone(QStringView str, const QDateTime &when,
int maxVal, int minVal) const
{
+ // Short-cut Zulu suffix when it's all there is (rather than a prefix match):
+ if (str == QLatin1Char('Z'))
+ return ParsedSection(Acceptable, 0, 1);
+
ParsedSection section = findUtcOffset(str);
if (section.used <= 0) // if nothing used, try time zone parsing
section = findTimeZoneName(str, when);