From 6e89ed5a3c13c15b4e62eda7cf46acd8793e84f8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?M=C3=A5rten=20Nordheim?= Date: Tue, 1 Dec 2020 17:36:15 +0100 Subject: [PATCH] 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 --- src/corelib/time/qdatetimeparser.cpp | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) 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);