summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorEdward Welbourne <edward.welbourne@qt.io>2018-08-17 13:07:14 +0200
committerEdward Welbourne <edward.welbourne@qt.io>2018-08-20 09:26:10 +0000
commite4cee4bd572a95eff8d908fb0a1b8cd810f0934e (patch)
tree0f84eb2fb3570d8b3b8f27498caf3fb3997003c0 /src
parent67984b265a359a217c833938475a51c010057344 (diff)
Add some local const variables to save some repeated computation
QTimeZonePrivate::dataForLocalTime() makes repeated use of the times sixteen hours before and after the target local time, so compute those up front once instead of each time they're needed, giving them expressive names and making code terser. Change-Id: I4b682cc6de2adb98c3ee5489eec4b63ac1090961 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'src')
-rw-r--r--src/corelib/tools/qtimezoneprivate.cpp15
1 files changed, 7 insertions, 8 deletions
diff --git a/src/corelib/tools/qtimezoneprivate.cpp b/src/corelib/tools/qtimezoneprivate.cpp
index 44ecf9a6c9..de571d8d23 100644
--- a/src/corelib/tools/qtimezoneprivate.cpp
+++ b/src/corelib/tools/qtimezoneprivate.cpp
@@ -260,6 +260,8 @@ QTimeZonePrivate::Data QTimeZonePrivate::dataForLocalTime(qint64 forLocalMSecs,
const qint64 sixteenHoursInMSecs(16 * 3600 * 1000);
Q_STATIC_ASSERT(-sixteenHoursInMSecs / 1000 < QTimeZone::MinUtcOffsetSecs
&& sixteenHoursInMSecs / 1000 > QTimeZone::MaxUtcOffsetSecs);
+ const qint64 recent = forLocalMSecs - sixteenHoursInMSecs;
+ const qint64 imminent = forLocalMSecs + sixteenHoursInMSecs;
/*
Offsets are Local - UTC, positive to the east of Greenwich, negative to
the west; DST offset always exceeds standard offset, when DST applies.
@@ -327,7 +329,7 @@ QTimeZonePrivate::Data QTimeZonePrivate::dataForLocalTime(qint64 forLocalMSecs,
// Get a transition definitely before the local MSecs; usually all we need.
// Only around the transition times might we need another.
- Data tran = previousTransition(forLocalMSecs - sixteenHoursInMSecs);
+ Data tran = previousTransition(recent);
Q_ASSERT(forLocalMSecs < 0 || // Pre-epoch TZ info may be unavailable
forLocalMSecs - tran.offsetFromUtc * 1000 >= tran.atMSecsSinceEpoch);
Data nextTran = nextTransition(tran.atMSecsSinceEpoch);
@@ -343,8 +345,7 @@ QTimeZonePrivate::Data QTimeZonePrivate::dataForLocalTime(qint64 forLocalMSecs,
&& forLocalMSecs > nextTran.atMSecsSinceEpoch + nextTran.offsetFromUtc * 1000) {
Data newTran = nextTransition(nextTran.atMSecsSinceEpoch);
if (newTran.atMSecsSinceEpoch == invalidMSecs()
- || newTran.atMSecsSinceEpoch + newTran.offsetFromUtc * 1000
- > forLocalMSecs + sixteenHoursInMSecs) {
+ || newTran.atMSecsSinceEpoch + newTran.offsetFromUtc * 1000 > imminent) {
// Definitely not a relevant tansition: too far in the future.
break;
}
@@ -417,8 +418,8 @@ QTimeZonePrivate::Data QTimeZonePrivate::dataForLocalTime(qint64 forLocalMSecs,
/* Bracket and refine to discover offset. */
qint64 utcEpochMSecs;
- int early = offsetFromUtc(forLocalMSecs - sixteenHoursInMSecs);
- int late = offsetFromUtc(forLocalMSecs + sixteenHoursInMSecs);
+ int early = offsetFromUtc(recent);
+ int late = offsetFromUtc(imminent);
if (Q_LIKELY(early == late)) { // > 99% of the time
utcEpochMSecs = forLocalMSecs - early * 1000;
} else {
@@ -439,9 +440,7 @@ QTimeZonePrivate::Data QTimeZonePrivate::dataForLocalTime(qint64 forLocalMSecs,
utcEpochMSecs = forStd;
} else {
// Invalid forLocalMSecs: in spring-forward gap.
- const int dstStep = daylightTimeOffset(early < late ?
- forLocalMSecs + sixteenHoursInMSecs :
- forLocalMSecs - sixteenHoursInMSecs);
+ const int dstStep = daylightTimeOffset(early < late ? imminent : recent);
Q_ASSERT(dstStep); // There can't be a transition without it !
utcEpochMSecs = (hint > 0) ? forStd - dstStep : forDst + dstStep;
}