Chromium Code Reviews| Index: src/date-delay.js |
| =================================================================== |
| --- src/date-delay.js (revision 2370) |
| +++ src/date-delay.js (working copy) |
| @@ -427,6 +427,18 @@ |
| } |
| +// The Date cache is used to limit the cost of parsing the same Date |
| +// strings over and over again. |
| +var Date_cache = { |
| + // Cached time value. |
| + time: $NaN, |
| + // Cached year. Only valid when the time matches cached time. |
|
bak
2009/07/07 11:54:02
Year when interpreting time as a local time.
|
| + year: $NaN, |
| + // String input for which the cached time is valid. |
| + string: null |
| +}; |
| + |
| + |
| %SetCode($Date, function(year, month, date, hours, minutes, seconds, ms) { |
| if (!%_IsConstructCall()) { |
| // ECMA 262 - 15.9.2 |
| @@ -442,6 +454,20 @@ |
| } else if (argc == 1) { |
| if (IS_NUMBER(year)) { |
| value = TimeClip(year); |
| + |
| + } else if (IS_STRING(year)) { |
| + // Probe the Date cache. If we already have a time value for the |
| + // given time, we re-use that instead of parsing the string again. |
| + var cache = Date_cache; |
| + if (cache.string === year) { |
| + value = cache.time; |
| + } else { |
| + value = DateParse(year); |
| + cache.time = value; |
| + cache.year = YearFromTime(LocalTimeNoCheck(value)); |
| + cache.string = year; |
| + } |
| + |
| } else { |
| // According to ECMA 262, no hint should be given for this |
| // conversion. However, ToPrimitive defaults to STRING_HINT for |
| @@ -537,8 +563,9 @@ |
| function GetFullYearFrom(aDate) { |
| var t = DATE_VALUE(aDate); |
| if (NUMBER_IS_NAN(t)) return t; |
| - // Ignore the DST offset for year computations. |
| - return YearFromTime(t + local_time_offset); |
| + var cache = Date_cache; |
| + if (cache.time === t) return cache.year; |
| + return YearFromTime(LocalTimeNoCheck(t)); |
| } |
| @@ -634,7 +661,7 @@ |
| // ------------------------------------------------------------------- |
| -// Reused output buffer. |
| +// Reused output buffer. Used when parsing date strings. |
| var parse_buffer = $Array(7); |
| // ECMA 262 - 15.9.4.2 |