time: another speedup
Huw D M Davies
h.davies1 at physics.ox.ac.uk
Tue Feb 24 06:11:57 CST 2004
Huw Davies <huw at codeweavers.com>
Speed up RtlTimeFieldsToTime
--
Huw Davies
huw at codeweavers.com
Index: dlls/ntdll/time.c
===================================================================
RCS file: /home/wine/wine/dlls/ntdll/time.c,v
retrieving revision 1.37
diff -u -r1.37 time.c
--- dlls/ntdll/time.c 24 Feb 2004 01:01:27 -0000 1.37
+++ dlls/ntdll/time.c 24 Feb 2004 12:09:05 -0000
@@ -284,7 +284,6 @@
#define TICKS_1601_TO_1980 (SECS_1601_TO_1980 * TICKSPERSEC)
-static const int YearLengths[2] = {DAYSPERNORMALYEAR, DAYSPERLEAPYEAR};
static const int MonthLengths[2][MONSPERYEAR] =
{
{ 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 },
@@ -421,7 +420,7 @@
PTIME_FIELDS tfTimeFields,
PLARGE_INTEGER Time)
{
- int CurYear, CurMonth;
+ int CurYear, CurMonth, DeltaYear;
LONGLONG rcTime;
TIME_FIELDS TimeFields = *tfTimeFields;
@@ -445,9 +444,18 @@
}
/* FIXME: handle calendar corrections here */
- for (CurYear = EPOCHYEAR; CurYear < TimeFields.Year; CurYear++)
- { rcTime += YearLengths[IsLeapYear(CurYear)];
- }
+ CurYear = TimeFields.Year - EPOCHYEAR;
+ DeltaYear = CurYear / 400;
+ CurYear -= DeltaYear * 400;
+ rcTime += DeltaYear * DAYSPERQUADRICENTENNIUM;
+ DeltaYear = CurYear / 100;
+ CurYear -= DeltaYear * 100;
+ rcTime += DeltaYear * DAYSPERNORMALCENTURY;
+ DeltaYear = CurYear / 4;
+ CurYear -= DeltaYear * 4;
+ rcTime += DeltaYear * DAYSPERNORMALQUADRENNIUM;
+ rcTime += CurYear * DAYSPERNORMALYEAR;
+
for (CurMonth = 1; CurMonth < TimeFields.Month; CurMonth++)
{ rcTime += MonthLengths[IsLeapYear(CurYear)][CurMonth - 1];
}
@@ -460,7 +468,6 @@
return TRUE;
}
-/************ end of code by Rex Jolliff (rex at lvcablemodem.com) ***************/
/******************************************************************************
* RtlLocalTimeToSystemTime [NTDLL.@]
More information about the wine-patches
mailing list