sal/osl/w32/time.cxx | 36 ++++++++++++++++++++---------------- 1 file changed, 20 insertions(+), 16 deletions(-)
New commits: commit f65905dd0ff464774f338db44d69925f98e1766c Author: Mike Kaganski <mike.kagan...@collabora.com> AuthorDate: Tue Jul 9 01:09:35 2019 +0200 Commit: Mike Kaganski <mike.kagan...@collabora.com> CommitDate: Tue Jul 9 02:03:44 2019 +0200 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.kagan...@collabora.com> 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); _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits