Speed up RtlTimeToTimeFields.
This commit is contained in:
parent
4fe98c5af0
commit
166faa455d
|
@ -272,6 +272,9 @@ static const struct tagTZ_INFO TZ_INFO[] =
|
||||||
#define DAYSPERNORMALYEAR 365
|
#define DAYSPERNORMALYEAR 365
|
||||||
#define DAYSPERLEAPYEAR 366
|
#define DAYSPERLEAPYEAR 366
|
||||||
#define MONSPERYEAR 12
|
#define MONSPERYEAR 12
|
||||||
|
#define DAYSPERQUADRICENTENNIUM (365 * 400 + 97)
|
||||||
|
#define DAYSPERNORMALCENTURY (365 * 100 + 24)
|
||||||
|
#define DAYSPERNORMALQUADRENNIUM (365 * 4 + 1)
|
||||||
|
|
||||||
/* 1601 to 1970 is 369 years plus 89 leap days */
|
/* 1601 to 1970 is 369 years plus 89 leap days */
|
||||||
#define SECS_1601_TO_1970 ((369 * 365 + 89) * (ULONGLONG)SECSPERDAY)
|
#define SECS_1601_TO_1970 ((369 * 365 + 89) * (ULONGLONG)SECSPERDAY)
|
||||||
|
@ -350,7 +353,7 @@ VOID WINAPI RtlTimeToTimeFields(
|
||||||
PTIME_FIELDS TimeFields)
|
PTIME_FIELDS TimeFields)
|
||||||
{
|
{
|
||||||
const int *Months;
|
const int *Months;
|
||||||
int SecondsInDay, CurYear;
|
int SecondsInDay, DeltaYear;
|
||||||
int LeapYear, CurMonth;
|
int LeapYear, CurMonth;
|
||||||
long int Days;
|
long int Days;
|
||||||
LONGLONG Time = liTime->QuadPart;
|
LONGLONG Time = liTime->QuadPart;
|
||||||
|
@ -376,17 +379,22 @@ VOID WINAPI RtlTimeToTimeFields(
|
||||||
TimeFields->Weekday = (CSHORT) ((EPOCHWEEKDAY + Days) % DAYSPERWEEK);
|
TimeFields->Weekday = (CSHORT) ((EPOCHWEEKDAY + Days) % DAYSPERWEEK);
|
||||||
|
|
||||||
/* compute year */
|
/* compute year */
|
||||||
CurYear = EPOCHYEAR;
|
|
||||||
/* FIXME: handle calendar modifications */
|
/* FIXME: handle calendar modifications */
|
||||||
while (1)
|
TimeFields->Year = EPOCHYEAR;
|
||||||
{ LeapYear = IsLeapYear(CurYear);
|
DeltaYear = Days / DAYSPERQUADRICENTENNIUM;
|
||||||
if (Days < (long) YearLengths[LeapYear])
|
TimeFields->Year += DeltaYear * 400;
|
||||||
{ break;
|
Days -= DeltaYear * DAYSPERQUADRICENTENNIUM;
|
||||||
}
|
DeltaYear = Days / DAYSPERNORMALCENTURY;
|
||||||
CurYear++;
|
TimeFields->Year += DeltaYear * 100;
|
||||||
Days = Days - (long) YearLengths[LeapYear];
|
Days -= DeltaYear * DAYSPERNORMALCENTURY;
|
||||||
}
|
DeltaYear = Days / DAYSPERNORMALQUADRENNIUM;
|
||||||
TimeFields->Year = (CSHORT) CurYear;
|
TimeFields->Year += DeltaYear * 4;
|
||||||
|
Days -= DeltaYear * DAYSPERNORMALQUADRENNIUM;
|
||||||
|
DeltaYear = Days / DAYSPERNORMALYEAR;
|
||||||
|
TimeFields->Year += DeltaYear;
|
||||||
|
Days -= DeltaYear * DAYSPERNORMALYEAR;
|
||||||
|
|
||||||
|
LeapYear = IsLeapYear(TimeFields->Year);
|
||||||
|
|
||||||
/* Compute month of year */
|
/* Compute month of year */
|
||||||
Months = MonthLengths[LeapYear];
|
Months = MonthLengths[LeapYear];
|
||||||
|
|
Loading…
Reference in New Issue