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>
This commit is contained in:
parent
e22adfad19
commit
f65905dd0f
@ -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;
|
||||
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;
|
||||
|
||||
SystemTimeToFileTime(&SystemTime, &OffTime);
|
||||
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);
|
||||
|
Loading…
x
Reference in New Issue
Block a user