summaryrefslogtreecommitdiff
path: root/sal
diff options
context:
space:
mode:
authorMike Kaganski <mike.kaganski@collabora.com>2019-07-09 01:09:35 +0200
committerMike Kaganski <mike.kaganski@collabora.com>2019-07-09 02:03:44 +0200
commitf65905dd0ff464774f338db44d69925f98e1766c (patch)
tree52e22a8cb60fa3bb8f3ee226b8c7df5eddb08387 /sal
parente22adfad195c22e98a47fd09c439ec96da247488 (diff)
Optimize osl_getSystemTime on Windows
Make OffTime static const; don't cast from FILETIME to __int64 (see https://docs.microsoft.com/en-us/windows/win32/api/minwinbase/ns-minwinbase-filetime for explanation: "it can cause alignment faults on 64-bit Windows"). Instead, cast in opposite direction: from 8-byte-aligned 64-bit integer to FILETIME. Change-Id: Iba61cc0198f8f25ef471d87e661c8801724b913d Reviewed-on: https://gerrit.libreoffice.org/75256 Tested-by: Jenkins Reviewed-by: Mike Kaganski <mike.kaganski@collabora.com>
Diffstat (limited to 'sal')
-rw-r--r--sal/osl/w32/time.cxx36
1 files changed, 20 insertions, 16 deletions
diff --git a/sal/osl/w32/time.cxx b/sal/osl/w32/time.cxx
index 135aab368fc8..ae499dcf8a8c 100644
--- a/sal/osl/w32/time.cxx
+++ b/sal/osl/w32/time.cxx
@@ -29,9 +29,7 @@
sal_Bool SAL_CALL osl_getSystemTime(TimeValue* pTimeVal)
{
- SYSTEMTIME SystemTime;
- FILETIME CurTime, OffTime;
- __int64 Value;
+ unsigned __int64 CurTime;
typedef VOID (WINAPI *GetSystemTimePreciseAsFileTime_PROC)(LPFILETIME);
@@ -46,25 +44,31 @@ sal_Bool SAL_CALL osl_getSystemTime(TimeValue* pTimeVal)
// use ~1 microsecond resolution if available
if (pGetSystemTimePreciseAsFileTime)
- pGetSystemTimePreciseAsFileTime(&CurTime);
+ pGetSystemTimePreciseAsFileTime(reinterpret_cast<LPFILETIME>(&CurTime));
else
{
+ SYSTEMTIME SystemTime;
GetSystemTime(&SystemTime);
- SystemTimeToFileTime(&SystemTime, &CurTime);
+ SystemTimeToFileTime(&SystemTime, reinterpret_cast<LPFILETIME>(&CurTime));
}
- SystemTime.wYear = 1970;
- SystemTime.wMonth = 1;
- SystemTime.wDayOfWeek = 0;
- SystemTime.wDay = 1;
- SystemTime.wHour = 0;
- SystemTime.wMinute = 0;
- SystemTime.wSecond = 0;
- SystemTime.wMilliseconds = 0;
-
- SystemTimeToFileTime(&SystemTime, &OffTime);
+ static const unsigned __int64 OffTime = [] {
+ SYSTEMTIME SystemTime;
+ SystemTime.wYear = 1970;
+ SystemTime.wMonth = 1;
+ SystemTime.wDayOfWeek = 0;
+ SystemTime.wDay = 1;
+ SystemTime.wHour = 0;
+ SystemTime.wMinute = 0;
+ SystemTime.wSecond = 0;
+ SystemTime.wMilliseconds = 0;
+
+ unsigned __int64 ft;
+ SystemTimeToFileTime(&SystemTime, reinterpret_cast<LPFILETIME>(&ft));
+ return ft;
+ }();
- Value = *reinterpret_cast<__int64 *>(&CurTime) - *reinterpret_cast<__int64 *>(&OffTime);
+ const unsigned __int64 Value = CurTime - OffTime;
pTimeVal->Seconds = static_cast<unsigned long>(Value / 10000000L);
pTimeVal->Nanosec = static_cast<unsigned long>((Value % 10000000L) * 100);