зеркало из https://github.com/mozilla/pjs.git
Bug 585866 - Avoid unnecessary calls to YearFromTime(). r=jwalden.
This commit is contained in:
Родитель
e994ce4ac5
Коммит
1b020d1c56
|
@ -189,8 +189,23 @@ TimeWithinDay(jsdouble t)
|
|||
return result;
|
||||
}
|
||||
|
||||
#define DaysInYear(y) ((y) % 4 == 0 && ((y) % 100 || ((y) % 400 == 0)) \
|
||||
? 366 : 365)
|
||||
static inline bool
|
||||
IsLeapYear(jsint year)
|
||||
{
|
||||
return year % 4 == 0 && (year % 100 || (year % 400 == 0));
|
||||
}
|
||||
|
||||
static inline jsint
|
||||
DaysInYear(jsint year)
|
||||
{
|
||||
return IsLeapYear(year) ? 366 : 365;
|
||||
}
|
||||
|
||||
static inline jsint
|
||||
DaysInFebruary(jsint year)
|
||||
{
|
||||
return IsLeapYear(year) ? 29 : 28;
|
||||
}
|
||||
|
||||
/* math here has to be f.p, because we need
|
||||
* floor((1968 - 1969) / 4) == -1
|
||||
|
@ -219,8 +234,6 @@ YearFromTime(jsdouble t)
|
|||
return y;
|
||||
}
|
||||
|
||||
#define InLeapYear(t) (JSBool) (DaysInYear(YearFromTime(t)) == 366)
|
||||
|
||||
#define DayWithinYear(t, year) ((intN) (Day(t) - DayFromYear(year)))
|
||||
|
||||
/*
|
||||
|
@ -237,7 +250,7 @@ static jsdouble firstDayOfMonth[2][13] = {
|
|||
static intN
|
||||
DaysInMonth(jsint year, jsint month)
|
||||
{
|
||||
JSBool leap = (DaysInYear(year) == 366);
|
||||
JSBool leap = IsLeapYear(year);
|
||||
intN result = intN(DayFromMonth(month, leap) - DayFromMonth(month-1, leap));
|
||||
return result;
|
||||
}
|
||||
|
@ -251,8 +264,7 @@ MonthFromTime(jsdouble t)
|
|||
|
||||
if (d < (step = 31))
|
||||
return 0;
|
||||
step += (InLeapYear(t) ? 29 : 28);
|
||||
if (d < step)
|
||||
if (d < (step += DaysInFebruary(year)))
|
||||
return 1;
|
||||
if (d < (step += 31))
|
||||
return 2;
|
||||
|
@ -285,8 +297,7 @@ DateFromTime(jsdouble t)
|
|||
if (d <= (next = 30))
|
||||
return d + 1;
|
||||
step = next;
|
||||
next += (InLeapYear(t) ? 29 : 28);
|
||||
if (d <= next)
|
||||
if (d <= (next += DaysInFebruary(year)))
|
||||
return d - step;
|
||||
step = next;
|
||||
if (d <= (next += 31))
|
||||
|
@ -346,7 +357,7 @@ MakeDay(jsdouble year, jsdouble month, jsdouble date)
|
|||
if (month < 0)
|
||||
month += 12;
|
||||
|
||||
leap = (DaysInYear((jsint) year) == 366);
|
||||
leap = IsLeapYear((jsint) year);
|
||||
|
||||
yearday = floor(TimeFromYear(year) / msPerDay);
|
||||
monthday = DayFromMonth(month, leap);
|
||||
|
@ -381,16 +392,13 @@ static jsint
|
|||
EquivalentYearForDST(jsint year)
|
||||
{
|
||||
jsint day;
|
||||
JSBool isLeapYear;
|
||||
|
||||
day = (jsint) DayFromYear(year) + 4;
|
||||
day = day % 7;
|
||||
if (day < 0)
|
||||
day += 7;
|
||||
|
||||
isLeapYear = (DaysInYear(year) == 366);
|
||||
|
||||
return yearStartingWith[isLeapYear][day];
|
||||
return yearStartingWith[IsLeapYear(year)][day];
|
||||
}
|
||||
|
||||
/* LocalTZA gets set by js_InitDateClass() */
|
||||
|
|
Загрузка…
Ссылка в новой задаче